f26ab702de
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
32 lines
706 B
TypeScript
32 lines
706 B
TypeScript
import { create } from 'zustand';
|
|
import { User } from '@/lib/api';
|
|
|
|
interface AuthState {
|
|
user: User | null;
|
|
isAuthenticated: boolean;
|
|
isLoading: boolean;
|
|
setUser: (user: User | null) => void;
|
|
setLoading: (loading: boolean) => void;
|
|
logout: () => void;
|
|
}
|
|
|
|
export const useAuthStore = create<AuthState>((set) => ({
|
|
user: null,
|
|
isAuthenticated: false,
|
|
isLoading: true,
|
|
|
|
setUser: (user) => set({
|
|
user,
|
|
isAuthenticated: !!user,
|
|
isLoading: false,
|
|
}),
|
|
|
|
setLoading: (loading) => set({ isLoading: loading }),
|
|
|
|
logout: () => {
|
|
localStorage.removeItem('access_token');
|
|
localStorage.removeItem('user');
|
|
set({ user: null, isAuthenticated: false });
|
|
},
|
|
}));
|