From 4ca03d00668b1851e8bd85f1e6b6003b051a722f Mon Sep 17 00:00:00 2001 From: Antoine Moreaux Date: Fri, 10 Jan 2025 17:21:33 +0100 Subject: [PATCH] fix(auth): handle error properly in loadCurrentUser (#9539) Updated the loadCurrentUser function to throw specific errors when an API error occurs. This improves clarity and error handling, replacing the generic "No current user result" exception. Fix #9536 --- packages/twenty-front/src/modules/auth/hooks/useAuth.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts index d583e815d..5646d5a2f 100644 --- a/packages/twenty-front/src/modules/auth/hooks/useAuth.ts +++ b/packages/twenty-front/src/modules/auth/hooks/useAuth.ts @@ -177,6 +177,10 @@ export const useAuth = () => { const loadCurrentUser = useCallback(async () => { const currentUserResult = await getCurrentUser(); + if (isDefined(currentUserResult.error)) { + throw new Error(currentUserResult.error.message); + } + const user = currentUserResult.data?.currentUser; if (!user) {