feat: connect admin session and public config endpoints
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user