From 3d9c71a8a25e99867cb6805cf59f02dab32ea82f Mon Sep 17 00:00:00 2001 From: "Kai (Tam Nhu) Tran" <61256810+kaitranntt@users.noreply.github.com> Date: Sat, 4 Apr 2026 20:19:11 -0400 Subject: [PATCH] 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 --- ui/web/src/stores/use-auth-store.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/web/src/stores/use-auth-store.ts b/ui/web/src/stores/use-auth-store.ts index 1519a57b..fe3b1c92 100644 --- a/ui/web/src/stores/use-auth-store.ts +++ b/ui/web/src/stores/use-auth-store.ts @@ -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()( tenantSlug: "", isOwner: false, availableTenants: [], - tenantSelected: false, + tenantSelected: !!localStorage.getItem(LOCAL_STORAGE_KEYS.TENANT_ID), setCredentials: (token, userId) => { set({ token, userId });