From 42d8191c1a176e8514f2f922a55dd5dacf0a4ff1 Mon Sep 17 00:00:00 2001 From: robin Date: Thu, 18 Dec 2025 21:28:46 +0100 Subject: [PATCH] fix(pwa): add visibilitychange listener for Android sleep issues --- src/app/page.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 () => {