diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index d72ef6ed..ba4e839a 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -84,8 +84,20 @@ function AuthGuard({ children }: { children: React.ReactNode }) { analyticsConsentShownAt, } = useAuth(); const storeConsent = useAnalyticsStore((s) => s.consent); + const setStoreConsent = useAnalyticsStore((s) => s.setConsent); const location = useLocation(); + // Hydrate the analytics store from session data on initial load + useEffect(() => { + if (!loading && analyticsEnabled !== undefined) { + setStoreConsent({ + analyticsEnabled: analyticsEnabled ?? null, + analyticsConsentShownAt: analyticsConsentShownAt ?? null, + analyticsConsentRemindAt: null, + }); + } + }, [loading, analyticsEnabled, analyticsConsentShownAt, setStoreConsent]); + // Don't guard the login or change-password pages if ( location.pathname === "/login" ||