Skip to content

Commit

Permalink
fix(core): catch auth error
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Mar 15, 2024
1 parent e35f6dc commit 9b7c607
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/frontend/core/src/hooks/affine/use-current-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ export async function getSession(
}

logger.error('Failed to fetch session', res.statusText);
return { user: null };
throw new Error('Failed to fetch session');
} catch (e) {
logger.error('Failed to fetch session', e);
return { user: null };
throw new Error('Failed to fetch session');
}
}

export function useSession(): Session {
const { data, mutate, isLoading } = useSWR('session', () => getSession());
const {
data,
mutate,
isLoading,
error: _error, // use error here to avoid uncaught error in the console
} = useSWR('session', () => getSession(), {
errorRetryCount: 3,
errorRetryInterval: 500,
shouldRetryOnError: true,
suspense: false,
});

return {
user: data?.user,
Expand Down

0 comments on commit 9b7c607

Please sign in to comment.