Skip to content

Commit

Permalink
fix(core): user info should be updated when session reloaded (#6382)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Mar 29, 2024
1 parent 0abd246 commit 605a5ab
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/frontend/core/src/hooks/affine/use-current-user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DebugLogger } from '@affine/debug';
import { getBaseUrl } from '@affine/graphql';
import { useMemo, useReducer } from 'react';
import { useEffect, useMemo, useReducer } from 'react';
import useSWR from 'swr';

import { SessionFetchErrorRightAfterLoginOrSignUp } from '../../unexpected-application-state/errors';
Expand Down Expand Up @@ -145,6 +145,21 @@ export function useCurrentUser(): CheckedUser {
[dispatcher, session]
);

// update user when session reloaded
// maybe lift user state up to global state?
useEffect(() => {
if (session.user) {
dispatcher({ type: 'update', payload: session.user });
} else {
dispatcher({ type: 'fetchError', payload: null });
}
}, [
session.user,
session.user?.id,
session.user?.name,
session.user?.avatarUrl,
]);

return useMemo(
() => ({
...user,
Expand Down

0 comments on commit 605a5ab

Please sign in to comment.