Skip to content

Commit

Permalink
Merge pull request #369 from mineadmin/fix(refresh_token)
Browse files Browse the repository at this point in the history
fix(refresh_token): 修复刷新token也失效的情况下,导致一直在加载页面转圈
  • Loading branch information
kanyxmo authored Oct 24, 2024
2 parents 9e011a7 + 6dc7519 commit 612da4e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions web/src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,23 @@ http.interceptors.response.use(
Authorization: `Bearer ${cache.get('refresh_token')}`,
},
}).post('/admin/passport/refresh')
const { data } = refreshTokenResponse.data
userStore.token = data.access_token
cache.set('token', data.access_token)
cache.set('expire', useDayjs().unix() + data.expire_at, { exp: data.expire_at })
cache.set('refresh_token', data.refresh_token)

config.headers!.Authorization = `Bearer ${userStore.token}`
requestList.value.map((cb: any) => cb())
requestList.value = []
return http(config)
if (refreshTokenResponse.data.code !== 200) {
await logout()
break
}
else {
const { data } = refreshTokenResponse.data
userStore.token = data.access_token
cache.set('token', data.access_token)
cache.set('expire', useDayjs().unix() + data.expire_at, { exp: data.expire_at })
cache.set('refresh_token', data.refresh_token)

config.headers!.Authorization = `Bearer ${userStore.token}`
requestList.value.map((cb: any) => cb())
requestList.value = []
return http(config)
}
}
// eslint-disable-next-line unused-imports/no-unused-vars
catch (e: any) {
Expand Down

0 comments on commit 612da4e

Please sign in to comment.