Files
Aether/frontend/src/store/authStore.ts
T

26 lines
624 B
TypeScript

import { create } from 'zustand';
interface User {
id: string;
email: string;
username: string;
}
interface AuthStore {
user: User | null;
isAuthenticated: boolean;
isLoading: boolean;
setUser: (user: User | null) => void;
setLoading: (loading: boolean) => void;
logout: () => void;
}
export const useAuthStore = create<AuthStore>((set) => ({
user: null,
isAuthenticated: false,
isLoading: true,
setUser: (user) => set({ user, isAuthenticated: !!user, isLoading: false }),
setLoading: (loading) => set({ isLoading: loading }),
logout: () => set({ user: null, isAuthenticated: false }),
}));