mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 15:31:12 -05:00
Fix: Ensure loading state is set correctly for session events in AuthProvider
This commit is contained in:
@@ -1185,14 +1185,19 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
console.log('📱 Tab visible - resuming queue updates');
|
||||
pauseFetchingRef.current = false;
|
||||
|
||||
// Check admin setting for auto-refresh behavior
|
||||
// CRITICAL: Check admin setting for auto-refresh behavior
|
||||
const shouldRefresh = refreshOnTabVisibleRef.current;
|
||||
|
||||
if (shouldRefresh && initialFetchCompleteRef.current && !isMountingRef.current) {
|
||||
console.log('🔄 Tab became visible - triggering refresh (admin setting enabled)');
|
||||
console.log('🔍 Tab visible check - shouldRefresh setting:', shouldRefresh,
|
||||
'initialFetchComplete:', initialFetchCompleteRef.current,
|
||||
'isMounting:', isMountingRef.current);
|
||||
|
||||
// Only refresh if admin setting explicitly enables it
|
||||
if (shouldRefresh === true && initialFetchCompleteRef.current && !isMountingRef.current) {
|
||||
console.log('🔄 Tab became visible - triggering refresh (admin setting ENABLED)');
|
||||
fetchItems(filtersRef.current.entityFilter, filtersRef.current.statusFilter, true, activeTabRef.current);
|
||||
} else {
|
||||
console.log('✅ Tab became visible - resuming without refresh');
|
||||
console.log('✅ Tab became visible - NO refresh (admin setting disabled or conditions not met)');
|
||||
// Realtime subscriptions will handle updates naturally
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,7 +301,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
}
|
||||
}
|
||||
|
||||
// Only set loading false immediately for events that don't need profile fetch
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user