diff --git a/src/frontend/apps/impress/src/features/auth/api/useAuthQuery.tsx b/src/frontend/apps/impress/src/features/auth/api/useAuthQuery.tsx index 714cc9e0..026beec9 100644 --- a/src/frontend/apps/impress/src/features/auth/api/useAuthQuery.tsx +++ b/src/frontend/apps/impress/src/features/auth/api/useAuthQuery.tsx @@ -1,6 +1,6 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query'; -import { APIError, fetchAPI } from '@/api'; +import { APIError, errorCauses, fetchAPI } from '@/api'; import { User } from './types'; @@ -17,7 +17,10 @@ import { User } from './types'; export const getMe = async (): Promise => { const response = await fetchAPI(`users/me/`); if (!response.ok) { - throw new Error(`Couldn't fetch user data: ${response.statusText}`); + throw new APIError( + `Couldn't fetch user data: ${response.statusText}`, + await errorCauses(response), + ); } return response.json() as Promise; }; diff --git a/src/frontend/apps/impress/src/features/auth/hooks/useAuth.tsx b/src/frontend/apps/impress/src/features/auth/hooks/useAuth.tsx index 6a13d514..a697a3cd 100644 --- a/src/frontend/apps/impress/src/features/auth/hooks/useAuth.tsx +++ b/src/frontend/apps/impress/src/features/auth/hooks/useAuth.tsx @@ -30,5 +30,10 @@ export const useAuth = () => { } }, [user, replace]); - return { user, authenticated: !!user, pathAllowed, ...authStates }; + return { + user, + authenticated: !!user && authStates.isSuccess, + pathAllowed, + ...authStates, + }; };