fix: 修复 AI 设计会话失效后的伪登录
问题:Main 刷新令牌返回 401 后已清空会话,但 Renderer 仍保留用户信息,AI 设计持续返回 AUTH_REQUIRED。 实现:认证初始化等待 Main 同步完成;同步或刷新失败清理登录态;Workspace 识别结构化认证错误并在重新登录后恢复加载;路由守卫响应登录状态变化。 验证:49 个聚焦测试通过,TypeScript、聚焦 Lint 与 Vite 生产构建通过。
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
import { IMAGE_WORKSPACE_CREATE_PROJECT_EVENT } from '@/lib/image-workspace';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useImageWorkspaceStore } from '@/stores/image-workspace';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import type { DesignWorkspaceSummary } from '../../../shared/image-workspace';
|
||||
|
||||
type ImageWorkspaceSidebarProps = {
|
||||
@@ -30,6 +31,7 @@ type ProjectDialogState =
|
||||
| { mode: 'rename'; project: DesignWorkspaceSummary };
|
||||
|
||||
export function ImageWorkspaceSidebar({ sidebarCollapsed }: ImageWorkspaceSidebarProps) {
|
||||
const authenticated = useAuthStore((state) => state.isAuthenticated());
|
||||
const navigate = useNavigate();
|
||||
const status = useImageWorkspaceStore((state) => state.status);
|
||||
const bootstrap = useImageWorkspaceStore((state) => state.bootstrap);
|
||||
@@ -46,8 +48,8 @@ export function ImageWorkspaceSidebar({ sidebarCollapsed }: ImageWorkspaceSideba
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (status === 'idle') void load();
|
||||
}, [load, status]);
|
||||
if (status === 'idle' || (status === 'auth-required' && authenticated)) void load();
|
||||
}, [authenticated, load, status]);
|
||||
|
||||
useEffect(() => {
|
||||
const openCreateDialog = () => {
|
||||
@@ -154,7 +156,7 @@ export function ImageWorkspaceSidebar({ sidebarCollapsed }: ImageWorkspaceSideba
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{status === 'unavailable' || status === 'error' ? (
|
||||
{status === 'unavailable' || status === 'error' || status === 'auth-required' ? (
|
||||
<div
|
||||
data-testid="sidebar-image-workspace-unavailable"
|
||||
className="rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-3 text-xs font-medium text-muted-foreground"
|
||||
|
||||
Reference in New Issue
Block a user