fix(ui): restore tenant selection state from localStorage on reload (#693)

The Zustand persist migration excluded tenantSelected from the
partialize whitelist, causing it to reset to false on page reload.
This created a redirect loop: require-auth saw the intermediate
state (connected + tenants loaded + tenantSelected=false) and
redirected to /select-tenant before the WS auto-select callback
could fire.

Restore the original localStorage-derived initialization so
tenantSelected is true immediately on rehydration when a tenant
scope was previously saved.

Closes #692
This commit is contained in:
Kai (Tam Nhu) Tran authored and GitHub committed 2026-04-05 07:19:11 +07:00
1 parent aa5158d4a2
commit 3d9c71a8a2
1 file changed
+2 -1
+2 -1
View File
@@ -1,5 +1,6 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { LOCAL_STORAGE_KEYS } from "@/lib/constants";
import { clearSetupSkippedState } from "@/lib/setup-skip";
import type { TenantMembership } from "@/types/tenant";
@@ -43,7 +44,7 @@ export const useAuthStore = create<AuthState>()(
tenantSlug: "",
isOwner: false,
availableTenants: [],
tenantSelected: false,
tenantSelected: !!localStorage.getItem(LOCAL_STORAGE_KEYS.TENANT_ID),
setCredentials: (token, userId) => {
set({ token, userId });