feat: add admin login

This commit is contained in:
yanghao05
2025-04-16 20:16:41 +08:00
parent e95fc65f5f
commit 4a9836db68
7 changed files with 88 additions and 14 deletions

View File

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