fix(pwa): add visibilitychange listener for Android sleep issues

This commit is contained in:
2025-12-18 21:28:46 +01:00
parent 087292f65d
commit 42d8191c1a

View File

@@ -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 () => {