Commit 3a5d1a5757c0a2be17e6dd370cbb023ddbb30d5e
1 parent
2c867b3d
fix: refresh failed while token invalid
修复当token失效时,刷新页面可能出现异常的问题 fixed: #1101
Showing
4 changed files
with
15 additions
and
7 deletions
CHANGELOG.zh_CN.md
src/router/guard/permissionGuard.ts
@@ -72,7 +72,12 @@ export function createPermissionGuard(router: Router) { | @@ -72,7 +72,12 @@ export function createPermissionGuard(router: Router) { | ||
72 | 72 | ||
73 | // get userinfo while last fetch time is empty | 73 | // get userinfo while last fetch time is empty |
74 | if (userStore.getLastUpdateTime === 0) { | 74 | if (userStore.getLastUpdateTime === 0) { |
75 | - await userStore.getUserInfoAction(); | 75 | + try { |
76 | + await userStore.getUserInfoAction(); | ||
77 | + } catch (err) { | ||
78 | + next(); | ||
79 | + return; | ||
80 | + } | ||
76 | } | 81 | } |
77 | 82 | ||
78 | if (permissionStore.getIsDynamicAddedRoute) { | 83 | if (permissionStore.getIsDynamicAddedRoute) { |
src/store/modules/user.ts
@@ -128,10 +128,12 @@ export const useUserStore = defineStore({ | @@ -128,10 +128,12 @@ export const useUserStore = defineStore({ | ||
128 | * @description: logout | 128 | * @description: logout |
129 | */ | 129 | */ |
130 | async logout(goLogin = false) { | 130 | async logout(goLogin = false) { |
131 | - try { | ||
132 | - await doLogout(); | ||
133 | - } catch { | ||
134 | - console.log('注销Token失败'); | 131 | + if (this.token) { |
132 | + try { | ||
133 | + await doLogout(); | ||
134 | + } catch { | ||
135 | + console.log('注销Token失败'); | ||
136 | + } | ||
135 | } | 137 | } |
136 | this.setToken(undefined); | 138 | this.setToken(undefined); |
137 | this.setSessionTimeout(false); | 139 | this.setSessionTimeout(false); |
src/utils/http/axios/checkStatus.ts
@@ -28,9 +28,9 @@ export function checkStatus( | @@ -28,9 +28,9 @@ export function checkStatus( | ||
28 | // Jump to the login page if not logged in, and carry the path of the current page | 28 | // Jump to the login page if not logged in, and carry the path of the current page |
29 | // Return to the current page after successful login. This step needs to be operated on the login page. | 29 | // Return to the current page after successful login. This step needs to be operated on the login page. |
30 | case 401: | 30 | case 401: |
31 | - errMessage = t('sys.api.errMsg401'); | 31 | + userStore.setToken(undefined); |
32 | + errMessage = msg || t('sys.api.errMsg401'); | ||
32 | if (stp === SessionTimeoutProcessingEnum.PAGE_COVERAGE) { | 33 | if (stp === SessionTimeoutProcessingEnum.PAGE_COVERAGE) { |
33 | - userStore.setToken(undefined); | ||
34 | userStore.setSessionTimeout(true); | 34 | userStore.setSessionTimeout(true); |
35 | } else { | 35 | } else { |
36 | userStore.logout(true); | 36 | userStore.logout(true); |