diff --git a/src/components/pages/studio/hooks/useBatchSubmit.ts b/src/components/pages/studio/hooks/useBatchSubmit.ts index 6a8a7017..518e48dc 100644 --- a/src/components/pages/studio/hooks/useBatchSubmit.ts +++ b/src/components/pages/studio/hooks/useBatchSubmit.ts @@ -9,7 +9,8 @@ import { hasActionLoras, } from "../constants/duration-options"; -const BATCH_SIZE = 5; +// Serialized to avoid concurrent auth refresh races (see fix/session-refresh-race on backend) +const BATCH_SIZE = 1; export const useBatchSubmit = () => { const images = useStudioStore((s) => s.images); diff --git a/src/hooks/useHttpInterceptors.ts b/src/hooks/useHttpInterceptors.ts index 19d27219..6e1646e6 100644 --- a/src/hooks/useHttpInterceptors.ts +++ b/src/hooks/useHttpInterceptors.ts @@ -28,6 +28,8 @@ type ResponseGeneratorProps = { logout: () => Promise; }; +let isLoggingOut = false; + const generateResponseInterceptor = async ({ logout, }: ResponseGeneratorProps) => { @@ -38,14 +40,17 @@ const generateResponseInterceptor = async ({ (response) => response, async (error) => { if (error?.response?.status === 401) { - // Handle unauthorized error - queryClient.clear(); - await logout(); - router.navigate(ROUTES.SIGNIN); + if (!isLoggingOut) { + isLoggingOut = true; + queryClient.clear(); + await logout(); + router.navigate(ROUTES.SIGNIN); + isLoggingOut = false; + } return Promise.reject(error); } - return error.response; + return Promise.reject(error); }, ); };