Fase 2: Implementación de Login, Store de Autenticación, Ruteo y Layout Protegido
This commit is contained in:
21
frontend/admin-panel/src/store/authStore.ts
Normal file
21
frontend/admin-panel/src/store/authStore.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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 });
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user