Fix: Synchronize user and profile state updates

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 17:01:15 +00:00
parent 8b1758e5e9
commit daf4f6bf19
2 changed files with 7 additions and 6 deletions

View File

@@ -191,6 +191,8 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
setSession(session);
setUser(session.user);
sessionVerifiedRef.current = true;
// Keep loading true until profile is fetched
setLoading(true);
} else if (event === 'INITIAL_SESSION') {
if (session?.user) {
authLog('[Auth] INITIAL_SESSION with user, setting session');
@@ -296,10 +298,9 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
profileFetchTimeoutRef.current = setTimeout(() => {
fetchProfile(session.user.id, 0, () => {
if (shouldWaitForProfile) {
authLog('[Auth] Profile fetch complete, setting loading to false');
setLoading(false);
}
// Always set loading to false after profile fetch for authenticated users
authLog('[Auth] Profile fetch complete, setting loading to false');
setLoading(false);
});
profileFetchTimeoutRef.current = null;
}, 0);