feat: add admin login
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { authService } from '@/api/authService';
|
||||
import { defineStore } from 'pinia';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
@@ -8,13 +7,12 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
const isAuthenticated = computed(() => !!token.value);
|
||||
|
||||
async function login(username, password) {
|
||||
const { data } = await authService.login(username, password);
|
||||
token.value = data.token;
|
||||
user.value = data.user;
|
||||
localStorage.setItem('token', data.token);
|
||||
function setToken(newToken) {
|
||||
token.value = newToken;
|
||||
localStorage.setItem('token', newToken);
|
||||
}
|
||||
|
||||
|
||||
function logout() {
|
||||
token.value = null;
|
||||
user.value = null;
|
||||
@@ -25,7 +23,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
token,
|
||||
user,
|
||||
isAuthenticated,
|
||||
login,
|
||||
logout
|
||||
logout,
|
||||
setToken
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user