24 lines
568 B
JavaScript
24 lines
568 B
JavaScript
// src/stores/authStore.js
|
|
import { defineStore } from 'pinia'
|
|
import { login } from '@/api/authApi'
|
|
|
|
export const useAuthStore = defineStore('auth', {
|
|
state: () => ({
|
|
token: localStorage.getItem('token') || null,
|
|
}),
|
|
actions: {
|
|
async loginUser(email, password) {
|
|
const data = await login(email, password)
|
|
this.token = data.access_token
|
|
localStorage.setItem('token', this.token)
|
|
},
|
|
logout() {
|
|
this.token = null
|
|
localStorage.removeItem('token')
|
|
},
|
|
isAuthenticated() {
|
|
return !!this.token
|
|
},
|
|
},
|
|
})
|