refactor(auth): 将认证状态迁移至独立登录 store

This commit is contained in:
yelan
2026-08-31 10:58:05 +08:00
parent a5e0a80191
commit a261a978f2
6 changed files with 111 additions and 73 deletions
+4 -5
View File
@@ -2,12 +2,12 @@
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getAuthErrorMessage, login as loginRequest } from '@/api/auth'
import { useAppStore } from '@/stores/app'
import { getAuthErrorMessage } from '@/api/auth'
import { useLoginStore } from '@/stores/login'
const route = useRoute()
const router = useRouter()
const appStore = useAppStore()
const loginStore = useLoginStore()
const username = ref('')
const password = ref('')
@@ -33,12 +33,11 @@ async function handleLogin() {
isSubmitting.value = true
try {
const session = await loginRequest({
await loginStore.login({
username: normalizedUsername,
password: password.value,
})
appStore.login(session)
await router.replace(getRedirectPath())
} catch (error: unknown) {
errorMessage.value = getAuthErrorMessage(error)