mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: AuthGuard checks analytics store for real-time consent state
This commit is contained in:
@@ -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 <Navigate to="/change-password" replace />;
|
||||
}
|
||||
|
||||
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 <Navigate to="/analytics-consent" replace />;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user