fix: all call user info
This commit is contained in:
@@ -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<AuthContextType>(() => {
|
||||
const loadingPhases: AuthPhase[] = [
|
||||
|
||||
Reference in New Issue
Block a user