mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 07:11:11 -05:00
Fix: Ensure loading state is set correctly for session events in AuthProvider
This commit is contained in:
@@ -189,6 +189,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
setUser(null);
|
||||
setProfile(null);
|
||||
sessionVerifiedRef.current = false;
|
||||
// CRITICAL: Set loading to false immediately when no session
|
||||
setLoading(false);
|
||||
}
|
||||
} else if (event === 'SIGNED_OUT') {
|
||||
@@ -292,7 +293,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
} else {
|
||||
if (isMountedRef.current) {
|
||||
setProfile(null);
|
||||
// If no session and this is an init event, resolve loading immediately
|
||||
// CRITICAL: Always resolve loading when there's no session
|
||||
if (event === 'INITIAL_SESSION' || event === 'SIGNED_OUT') {
|
||||
console.log('[Auth] No session for event:', event, '- setting loading to false');
|
||||
setLoading(false);
|
||||
@@ -300,11 +301,11 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
}
|
||||
}
|
||||
|
||||
// Only set loading false immediately for events that don't need profile fetch
|
||||
if (event !== 'SIGNED_IN' && event !== 'INITIAL_SESSION') {
|
||||
console.log('[Auth] Setting loading to false immediately for event:', event);
|
||||
setLoading(false);
|
||||
}
|
||||
// CRITICAL: Always set loading false for non-session events
|
||||
if (event !== 'SIGNED_IN' && event !== 'INITIAL_SESSION') {
|
||||
console.log('[Auth] Setting loading to false immediately for event:', event);
|
||||
setLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
// THEN get initial session
|
||||
@@ -417,4 +418,4 @@ export function useAuth() {
|
||||
throw new Error('useAuth must be used within an AuthProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user