刷新token调整
This commit is contained in:
parent
c77612e4dc
commit
c7d5464276
@ -7,9 +7,10 @@ import {
|
|||||||
} from 'vue-router';
|
} from 'vue-router';
|
||||||
|
|
||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
import { getJwtToken, saveJwtToken } from 'src/configs/TokenManage';
|
import { getJwtToken } from 'src/configs/TokenManage';
|
||||||
import { getUserInfo, refreshToken } from 'src/api/UserApi';
|
import { getUserInfo } from 'src/api/UserApi';
|
||||||
import { useUserStore } from 'src/stores/user-store';
|
import { useUserStore } from 'src/stores/user-store';
|
||||||
|
import { handleRefreshToken } from 'src/utils/refreshToken';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If not building with SSR mode, you can
|
* If not building with SSR mode, you can
|
||||||
@ -68,16 +69,3 @@ export default route(function (/* { store, ssrContext } */) {
|
|||||||
|
|
||||||
return Router;
|
return Router;
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function handleRefreshToken() {
|
|
||||||
try {
|
|
||||||
const tokenInfo = await refreshToken();
|
|
||||||
saveJwtToken(tokenInfo.token);
|
|
||||||
setTimeout(
|
|
||||||
() => handleRefreshToken(),
|
|
||||||
tokenInfo.remainingSecond * 1000 - 10000
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('刷新 token 出错:', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
18
src/utils/refreshToken.ts
Normal file
18
src/utils/refreshToken.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { saveJwtToken } from 'src/configs/TokenManage';
|
||||||
|
import { refreshToken } from 'src/api/UserApi';
|
||||||
|
import { useUserStore } from 'src/stores/user-store';
|
||||||
|
|
||||||
|
export async function handleRefreshToken() {
|
||||||
|
try {
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const tokenInfo = await refreshToken();
|
||||||
|
saveJwtToken(tokenInfo.token);
|
||||||
|
userStore.remainingSecond = tokenInfo.remainingSecond;
|
||||||
|
setTimeout(
|
||||||
|
() => handleRefreshToken(),
|
||||||
|
tokenInfo.remainingSecond * 1000 - 10000
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('刷新 token 出错:', e);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user