From 7d2e9ccb81ce4493799389ae7fa85b8935178444 Mon Sep 17 00:00:00 2001 From: Antoine Moreaux Date: Fri, 10 Jan 2025 15:49:39 +0100 Subject: [PATCH] fix(auth): handle error properly in loadCurrentUser 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. --- 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 d583e815d8eb..5646d5a2ff6c 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) {