diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 9754396c..d72ef6ed 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -83,6 +83,7 @@ function AuthGuard({ children }: { children: React.ReactNode }) { analyticsEnabled, analyticsConsentShownAt, } = useAuth(); + const storeConsent = useAnalyticsStore((s) => s.consent); const location = useLocation(); // Don't guard the login or change-password pages @@ -115,7 +116,12 @@ function AuthGuard({ children }: { children: React.ReactNode }) { return ; } - if (authEnabled && analyticsEnabled === null && analyticsConsentShownAt === null) { + // Check both session state (useAuth) and real-time store state. + // After the consent page calls acceptAnalytics(), the store updates immediately + // but useAuth won't re-fetch until the next session check. + const effectiveEnabled = storeConsent.analyticsEnabled ?? analyticsEnabled; + const effectiveShownAt = storeConsent.analyticsConsentShownAt ?? analyticsConsentShownAt; + if (authEnabled && effectiveEnabled === null && effectiveShownAt === null) { return ; }