mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-09-18 03:39:58 +08:00
28 lines
695 B
TypeScript
28 lines
695 B
TypeScript
import { fetchRefreshToken } from '@/service'
|
|
import { useAuthStore } from '@/store'
|
|
import { local } from '@/utils'
|
|
|
|
/**
|
|
* @description: 处理接口token刷新
|
|
* @return {*}
|
|
*/
|
|
export async function handleRefreshToken() {
|
|
const authStore = useAuthStore()
|
|
const isAutoRefresh = import.meta.env.VITE_AUTO_REFRESH_TOKEN === 'Y'
|
|
if (!isAutoRefresh) {
|
|
await authStore.logout()
|
|
return
|
|
}
|
|
|
|
// 刷新token
|
|
const { data } = await fetchRefreshToken({ refreshToken: local.get('refreshToken') })
|
|
if (data) {
|
|
local.set('accessToken', data.accessToken)
|
|
local.set('refreshToken', data.refreshToken)
|
|
}
|
|
else {
|
|
// 刷新失败,退出
|
|
await authStore.logout()
|
|
}
|
|
}
|