- 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>
27 lines
676 B
JavaScript
27 lines
676 B
JavaScript
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 }
|
|
})
|