Files
Generadordeguiones/frontend/src/stores/auth.js

27 lines
676 B
JavaScript
Raw Normal View History

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 }
})