mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-06-04 13:30:32 +08:00
After re-login, the JWT is minted with the user's last-active tenant (see userService.resolveLoginTenantID). Both TenantSelector and UserMenu used to clear weknora_selected_tenant_id when "switching to home", which made request.ts stop attaching X-Tenant-ID. Without the header, the auth middleware fell back to the JWT-encoded tenant id — i.e. the peer tenant the user just tried to leave — so the switch was silently a no-op until the user manually wiped localStorage and re-logged in. Always write the active tenant id into selectedTenantId so the "always attach X-Tenant-ID" invariant request.ts relies on stays true. The server-side last_active_tenant_id preference is still cleared when switching to home, so a clean re-login still lands the user on home. Also fix TenantSelector.defaultTenantId to read user.tenant_id (the immutable home id) instead of authStore.tenant.id (the active tenant, which is overwritten by /auth/me). This matches the contract spelled out in useHomeTenant() and prevents switchingToHome from misfiring when the active tenant differs from home.