import { create } from 'zustand' import type { User } from '../types/api.ts' export type AuthState = 'loading' | 'authenticated' | 'unauthenticated' | 'error' interface AuthStore { state: AuthState user: User | null error: Error | null setState: (state: AuthState) => void setUser: (user: User | null) => void setError: (error: Error | null) => void logout: () => void } export const useAuthStore = create((set) => ({ state: 'loading', user: null, error: null, setState: (state) => set({ state }), setUser: (user) => set({ user, state: user ? 'authenticated' : 'unauthenticated' }), setError: (error) => set({ error, state: 'error' }), logout: () => { localStorage.removeItem('access_token') set({ user: null, state: 'unauthenticated', error: null }) }, }))