fix: hydrate analytics store from session data on login

This commit is contained in:
ashim-hq
2026-04-23 10:08:24 +08:00
parent 7275e4bfaa
commit e46356c4d5
+12
View File
@@ -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" ||