fix: all call user info
This commit is contained in:
@@ -149,12 +149,18 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
let hasSynced = false;
|
||||||
|
|
||||||
const syncUserProfile = async () => {
|
const syncUserProfile = async () => {
|
||||||
if (!state.user || !state.token) {
|
const currentUser = state.user;
|
||||||
|
const currentToken = state.token;
|
||||||
|
|
||||||
|
if (!currentUser || !currentToken || hasSynced) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasSynced = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const profile = await authService.getUserInfo();
|
const profile = await authService.getUserInfo();
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
@@ -164,7 +170,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: 'UPDATE_USER',
|
type: 'UPDATE_USER',
|
||||||
payload: {
|
payload: {
|
||||||
user: mergeUserProfile(state.user, profile),
|
user: mergeUserProfile(currentUser, profile),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
@@ -177,7 +183,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [state.token, state.user]);
|
}, [state.token]);
|
||||||
|
|
||||||
const value = useMemo<AuthContextType>(() => {
|
const value = useMemo<AuthContextType>(() => {
|
||||||
const loadingPhases: AuthPhase[] = [
|
const loadingPhases: AuthPhase[] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user