mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 14:31:11 -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');
|
console.log('📱 Tab visible - resuming queue updates');
|
||||||
pauseFetchingRef.current = false;
|
pauseFetchingRef.current = false;
|
||||||
|
|
||||||
// Check admin setting for auto-refresh behavior
|
// CRITICAL: Check admin setting for auto-refresh behavior
|
||||||
const shouldRefresh = refreshOnTabVisibleRef.current;
|
const shouldRefresh = refreshOnTabVisibleRef.current;
|
||||||
|
|
||||||
if (shouldRefresh && initialFetchCompleteRef.current && !isMountingRef.current) {
|
console.log('🔍 Tab visible check - shouldRefresh setting:', shouldRefresh,
|
||||||
console.log('🔄 Tab became visible - triggering refresh (admin setting enabled)');
|
'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);
|
fetchItems(filtersRef.current.entityFilter, filtersRef.current.statusFilter, true, activeTabRef.current);
|
||||||
} else {
|
} 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
|
// Realtime subscriptions will handle updates naturally
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2511,4 +2516,4 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
ModerationQueue.displayName = 'ModerationQueue';
|
ModerationQueue.displayName = 'ModerationQueue';
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
|||||||
setUser(null);
|
setUser(null);
|
||||||
setProfile(null);
|
setProfile(null);
|
||||||
sessionVerifiedRef.current = false;
|
sessionVerifiedRef.current = false;
|
||||||
|
// CRITICAL: Set loading to false immediately when no session
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} else if (event === 'SIGNED_OUT') {
|
} else if (event === 'SIGNED_OUT') {
|
||||||
@@ -292,7 +293,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
|||||||
} else {
|
} else {
|
||||||
if (isMountedRef.current) {
|
if (isMountedRef.current) {
|
||||||
setProfile(null);
|
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') {
|
if (event === 'INITIAL_SESSION' || event === 'SIGNED_OUT') {
|
||||||
console.log('[Auth] No session for event:', event, '- setting loading to false');
|
console.log('[Auth] No session for event:', event, '- setting loading to false');
|
||||||
setLoading(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
|
// CRITICAL: Always set loading false for non-session events
|
||||||
if (event !== 'SIGNED_IN' && event !== 'INITIAL_SESSION') {
|
if (event !== 'SIGNED_IN' && event !== 'INITIAL_SESSION') {
|
||||||
console.log('[Auth] Setting loading to false immediately for event:', event);
|
console.log('[Auth] Setting loading to false immediately for event:', event);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// THEN get initial session
|
// THEN get initial session
|
||||||
@@ -417,4 +418,4 @@ export function useAuth() {
|
|||||||
throw new Error('useAuth must be used within an AuthProvider');
|
throw new Error('useAuth must be used within an AuthProvider');
|
||||||
}
|
}
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user