Files
SIG-CM/frontend/admin-panel/src/store/authStore.ts

22 lines
560 B
TypeScript
Raw Normal View History

import { create } from 'zustand';
interface AuthState {
token: string | null;
isAuthenticated: boolean;
setToken: (token: string) => void;
logout: () => void;
}
export const useAuthStore = create<AuthState>((set) => ({
token: localStorage.getItem('token'),
isAuthenticated: !!localStorage.getItem('token'),
setToken: (token: string) => {
localStorage.setItem('token', token);
set({ token, isAuthenticated: true });
},
logout: () => {
localStorage.removeItem('token');
set({ token: null, isAuthenticated: false });
},
}));