feat(auth): сбрасывать активную workspace при имперсонации и возврате
Some checks failed
Deploy to Production / Trigger production update (push) Has been cancelled

При смене токена (вход под пользователем / возврат к админу) сбрасываем
выбранную рабочую область через setActiveWorkspace(null): выбор
предыдущей личности передавался в хедере X-Active-Workspace и мог не
принадлежать новой. Дополняет уже существующий сброс кэша React Query.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
markmorado
2026-07-22 05:37:23 +05:00
parent 43336c02c7
commit d3b834cbe1

View File

@@ -1,6 +1,7 @@
import { create } from 'zustand';
import { apiClient } from '@/lib/api-client';
import { queryClient } from '@/lib/query-client';
import { useWorkspaceStore } from '@/stores/workspace-store';
import type { User, LoginRequest, AuthResponse } from '@/types';
interface AuthState {
@@ -27,6 +28,9 @@ async function switchToken(
): Promise<void> {
apiClient.setToken(token);
queryClient.clear();
// Reset the active workspace: the previous identity's selection (sent via the
// X-Active-Workspace header) may not belong to the new one.
useWorkspaceStore.getState().setActiveWorkspace(null);
set({ token, isAuthenticated: true });
const user = await apiClient.get<User>('/api/auth/me');
set({ user });