Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(core): catch auth error (#6128)

EYHN96c67afc1158
diff --git a/packages/frontend/core/src/hooks/affine/use-current-user.ts b/packages/frontend/core/src/hooks/affine/use-current-user.ts
index d4329d9ba6..6ec51fa8d4 100644
--- a/packages/frontend/core/src/hooks/affine/use-current-user.ts
+++ b/packages/frontend/core/src/hooks/affine/use-current-user.ts
@@ -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,