import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { Observable } from 'rxjs';
import { Response as ExpressResponse } from 'express';
@Injectable()
export class ResponseAddContentRangeToHeaderInterceptor implements NestInterceptor {
intercept(context:ExecutionContext, next:CallHandler): Observable<any> {
const ResponseObj:ExpressResponse = context.switchToHttp().getResponse();
ResponseObj.setHeader('Access-Control-Expose-Headers', 'Content-Range' );
return next.handle();
}
}
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalInterceptors(new ResponseAddContentRangeToHeaderInterceptor());
await app.listen(8080);
}
export const useVerifyAuth = () => {
const { setIsAuth, setUser, setIsLoading } = useUserStore();
const pathname = usePathname();
const { data, error, isLoading, isFetching, refetch } = useQuery({
queryKey: ["verify-auth"],
queryFn: () => authService.getNewTokens()
});
useLayoutEffect(() => {
if (error !== null) {
setIsAuth(false);
setUser(null);
}
if (data !== null) {
setIsAuth(true);
setUser(data.data.user);
}
}, [data, error])
useEffect(() => {
// Тут бы проверить, что прошлый pathname не равен текущему
refetch();
}, [pathname, refetch]);
useEffect(() => {
setIsLoading(isLoading || isFetching)
}, [isLoading, isFetching]);
};