From 7275e4bfaaedbbeebd07a0e1db434f718d307962 Mon Sep 17 00:00:00 2001 From: ashim-hq Date: Thu, 23 Apr 2026 10:06:46 +0800 Subject: [PATCH] fix: AuthGuard checks analytics store for real-time consent state --- apps/web/src/App.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 ; }