feat: sistema de autenticación con login, logout y guard de rutas
- Agrega LoginView con formulario de acceso - Agrega store de auth (Pinia) con estado isAuthenticated - Protege todas las rutas con beforeEach, redirige a /login si no autenticado - App.vue oculta nav/sidebar en rutas públicas - TopAppBar incluye botón de cerrar sesión Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
26
frontend/src/stores/auth.js
Normal file
26
frontend/src/stores/auth.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const ADMIN_EMAIL = 'admin@gmail.com'
|
||||
const ADMIN_PASSWORD = 'admin123'
|
||||
const STORAGE_KEY = 'auth_session'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const isAuthenticated = ref(!!localStorage.getItem(STORAGE_KEY))
|
||||
|
||||
function login(email, password) {
|
||||
if (email === ADMIN_EMAIL && password === ADMIN_PASSWORD) {
|
||||
localStorage.setItem(STORAGE_KEY, '1')
|
||||
isAuthenticated.value = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function logout() {
|
||||
localStorage.removeItem(STORAGE_KEY)
|
||||
isAuthenticated.value = false
|
||||
}
|
||||
|
||||
return { isAuthenticated, login, logout }
|
||||
})
|
||||
Reference in New Issue
Block a user