From a797b2b0d745928606583a9dffd39dfaf39e8457 Mon Sep 17 00:00:00 2001 From: yoge Date: Mon, 9 Mar 2026 21:13:01 +0800 Subject: [PATCH] fix: all call user info --- src/contexts/AuthContext.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 455e80e..281acc1 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -149,12 +149,18 @@ export function AuthProvider({ children }: { children: ReactNode }) { useEffect(() => { let cancelled = false; + let hasSynced = false; const syncUserProfile = async () => { - if (!state.user || !state.token) { + const currentUser = state.user; + const currentToken = state.token; + + if (!currentUser || !currentToken || hasSynced) { return; } + hasSynced = true; + try { const profile = await authService.getUserInfo(); if (cancelled) { @@ -164,7 +170,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { dispatch({ type: 'UPDATE_USER', payload: { - user: mergeUserProfile(state.user, profile), + user: mergeUserProfile(currentUser, profile), }, }); } catch { @@ -177,7 +183,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { return () => { cancelled = true; }; - }, [state.token, state.user]); + }, [state.token]); const value = useMemo(() => { const loadingPhases: AuthPhase[] = [