Complete implementation of the production line incident response system (生產線異常即時反應系統) including: Backend (FastAPI): - User authentication with AD integration and session management - Chat room management (create, list, update, members, roles) - Real-time messaging via WebSocket (typing indicators, reactions) - File storage with MinIO (upload, download, image preview) Frontend (React + Vite): - Authentication flow with token management - Room list with filtering, search, and pagination - Real-time chat interface with WebSocket - File upload with drag-and-drop and image preview - Member management and room settings - Breadcrumb navigation - 53 unit tests (Vitest) Specifications: - authentication: AD auth, sessions, JWT tokens - chat-room: rooms, members, templates - realtime-messaging: WebSocket, messages, reactions - file-storage: MinIO integration, file management - frontend-core: React SPA structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { create } from 'zustand'
|
|
import { persist } from 'zustand/middleware'
|
|
import type { User } from '../types'
|
|
|
|
interface AuthState {
|
|
token: string | null
|
|
user: User | null
|
|
isAuthenticated: boolean
|
|
|
|
// Actions
|
|
setAuth: (token: string, displayName: string, username: string) => void
|
|
clearAuth: () => void
|
|
updateUser: (user: Partial<User>) => void
|
|
}
|
|
|
|
export const useAuthStore = create<AuthState>()(
|
|
persist(
|
|
(set) => ({
|
|
token: null,
|
|
user: null,
|
|
isAuthenticated: false,
|
|
|
|
setAuth: (token: string, displayName: string, username: string) =>
|
|
set({
|
|
token,
|
|
user: { username, display_name: displayName },
|
|
isAuthenticated: true,
|
|
}),
|
|
|
|
clearAuth: () =>
|
|
set({
|
|
token: null,
|
|
user: null,
|
|
isAuthenticated: false,
|
|
}),
|
|
|
|
updateUser: (userData: Partial<User>) =>
|
|
set((state) => ({
|
|
user: state.user ? { ...state.user, ...userData } : null,
|
|
})),
|
|
}),
|
|
{
|
|
name: 'auth-storage',
|
|
partialize: (state) => ({
|
|
token: state.token,
|
|
user: state.user,
|
|
isAuthenticated: state.isAuthenticated,
|
|
}),
|
|
}
|
|
)
|
|
)
|