feat: connect admin session and public config endpoints

This commit is contained in:
Lan
2026-06-03 02:52:38 +08:00
parent 2a73e24d1c
commit 46e75f94b2
7 changed files with 83 additions and 7 deletions
+1
View File
@@ -1,5 +1,6 @@
export { useAdminFiles } from './useAdminFiles'
export { useAdminLogin } from './useAdminLogin'
export { useAdminSession } from './useAdminSession'
export { useAppShell } from './useAppShell'
export { useDashboardStats } from './useDashboardStats'
export { useInjectedDarkMode } from './useInjectedDarkMode'
+7 -1
View File
@@ -35,7 +35,13 @@ export function useAdminLogin() {
return false
}
adminStore.setToken(response.detail.token)
adminStore.login({
id: response.detail.id || 'admin',
username: response.detail.username || 'admin',
token: response.detail.token,
token_type: response.detail.token_type,
expires_at: response.detail.expires_at
})
return true
} catch (error: unknown) {
alertStore.showAlert(getErrorMessage(error, '登录失败'), 'error')
+35
View File
@@ -0,0 +1,35 @@
import { AuthService } from '@/services'
import { useAdminStore } from '@/stores/adminStore'
export function useAdminSession() {
const adminStore = useAdminStore()
const verifySession = async () => {
if (!adminStore.hasToken) return false
try {
const response = await AuthService.verifyToken()
if (response.code === 200 && response.detail?.token) {
adminStore.login(response.detail)
return true
}
} catch {
adminStore.logout()
}
return false
}
const logout = async () => {
try {
await AuthService.logout()
} finally {
adminStore.logout()
}
}
return {
verifySession,
logout
}
}