ready to deployment
This commit is contained in:
23
frontend/src/stores/authStore.js
Normal file
23
frontend/src/stores/authStore.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user