From 571c85f14fad20e70a8863e8c4d0f9ddfe419c8a Mon Sep 17 00:00:00 2001 From: Claw AI Date: Wed, 1 Apr 2026 15:29:41 +0000 Subject: [PATCH] fix: detect auth changes via polling and visibility change --- app/components/NotificationHandler.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/components/NotificationHandler.js b/app/components/NotificationHandler.js index 39ab995..820c25f 100644 --- a/app/components/NotificationHandler.js +++ b/app/components/NotificationHandler.js @@ -23,11 +23,11 @@ export default function NotificationHandler() { const initialized = useRef(false); useEffect(() => { - const timer = setTimeout(() => { + function checkAuth() { if (initialized.current) return; - initialized.current = true; if (!AuthService.getToken()) return; + initialized.current = true; if ("Notification" in window) { if (Notification.permission === "default") { @@ -36,9 +36,28 @@ export default function NotificationHandler() { setupFCM(); } } + } + + // Check immediately + checkAuth(); + + // Also check when auth token changes (login via client-side navigation) + const interval = setInterval(() => { + if (!initialized.current && AuthService.getToken()) { + checkAuth(); + } }, 1000); - return () => clearTimeout(timer); + // Check on route change (visibility) + const onVisibility = () => { + if (document.visibilityState === "visible") checkAuth(); + }; + document.addEventListener("visibilitychange", onVisibility); + + return () => { + clearInterval(interval); + document.removeEventListener("visibilitychange", onVisibility); + }; }, []); async function setupFCM() {