Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): catch auth error #6128

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading