Skip to content

Commit

Permalink
fix(auth): handle error properly in loadCurrentUser
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AMoreaux committed Jan 10, 2025
1 parent 5648c3b commit 04e2f84
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/twenty-front/src/modules/auth/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ export const useAuth = () => {
const loadCurrentUser = useCallback(async () => {
const currentUserResult = await getCurrentUser();

const user = currentUserResult.data?.currentUser;

if (!user) {
throw new Error('No current user result');
if (isDefined(currentUserResult.error)) {
throw new Error(currentUserResult.error.message);
}

const user = currentUserResult.data?.currentUser;

let workspaceMember = null;

setCurrentUser(user);
Expand Down

0 comments on commit 04e2f84

Please sign in to comment.