import { create } from 'zustand'; import { apiClient } from '../api/client'; interface AuthState { isAuthenticated: boolean; loading: boolean; checkAuth: () => Promise; login: (username: string, password: string) => Promise; logout: () => Promise; } export const useAuthStore = create((set) => ({ isAuthenticated: false, loading: true, checkAuth: async () => { try { await apiClient.auth.me(); set({ isAuthenticated: true, loading: false }); } catch { set({ isAuthenticated: false, loading: false }); } }, login: async (username, password) => { await apiClient.auth.login(username, password); set({ isAuthenticated: true }); }, logout: async () => { try { await apiClient.auth.logout(); } finally { set({ isAuthenticated: false }); } }, }));