Fase 2: Implementación de Login, Store de Autenticación, Ruteo y Layout Protegido

This commit is contained in:
2025-12-17 13:13:43 -03:00
parent 1c7e8d5cdb
commit f19cd781ad
7 changed files with 185 additions and 30 deletions

View 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 });
},
}));