diff --git a/src/app/page.tsx b/src/app/page.tsx index e4026f4..8e30046 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -54,6 +54,15 @@ export default function Home() { checkUser(); + // Listen for visibility change (wake up from sleep) + const handleVisibilityChange = () => { + if (document.visibilityState === 'visible') { + console.log('[Auth] App became visible, refreshing session...'); + checkUser(); + } + }; + document.addEventListener('visibilitychange', handleVisibilityChange); + // Listen for auth changes const { data: { subscription } } = supabase.auth.onAuthStateChange((event, session) => { console.log('[Auth] State change event:', event, { @@ -72,7 +81,10 @@ export default function Home() { } }); - return () => subscription.unsubscribe(); + return () => { + subscription.unsubscribe(); + document.removeEventListener('visibilitychange', handleVisibilityChange); + }; }, []); const fetchCollection = async () => {