stock-bot/apps/wcag-ada/dashboard/src/store/auth-store.ts
2025-06-28 11:11:34 -04:00

55 lines
No EOL
1.1 KiB
TypeScript

import { create } from 'zustand';
import { persist } from 'zustand/middleware';
interface User {
id: string;
email: string;
name?: string;
company?: string;
role: string;
apiKey?: string;
}
interface AuthState {
user: User | null;
token: string | null;
isAuthenticated: boolean;
isLoading: boolean;
setAuth: (user: User, token: string) => void;
setUser: (user: User) => void;
setLoading: (loading: boolean) => void;
logout: () => void;
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
user: null,
token: null,
isAuthenticated: false,
isLoading: true,
setAuth: (user, token) =>
set({
user,
token,
isAuthenticated: true,
isLoading: false,
}),
setUser: (user) => set({ user }),
setLoading: (loading) => set({ isLoading: loading }),
logout: () =>
set({
user: null,
token: null,
isAuthenticated: false,
isLoading: false,
}),
}),
{
name: 'wcag-auth',
partialize: (state) => ({
token: state.token,
}),
}
)
);