feat: refreshToken

pull/4/MERGE
xingyuv 2023-03-27 16:25:59 +08:00
parent 0ed8e09f2b
commit a640f3822f
1 changed files with 4 additions and 7 deletions

View File

@ -113,21 +113,18 @@ export class VAxios {
// 1. 获取到刷新token // 1. 获取到刷新token
if (getRefreshToken()) { if (getRefreshToken()) {
// 2. 进行刷新访问令牌 // 2. 进行刷新访问令牌
console.info('进行刷新访问令牌')
try { try {
const refreshTokenRes = await this.refreshToken() const refreshTokenRes = await this.refreshToken()
// 2.1 刷新成功,则回放队列的请求 + 当前请求 // 2.1 刷新成功,则回放队列的请求 + 当前请求
setAccessToken(refreshTokenRes.data.data) setAccessToken(refreshTokenRes.data.data.accessToken)
;(config as Recordable).headers.Authorization = 'Bearer ' + getAccessToken() ;(config as Recordable).headers.Authorization = 'Bearer ' + getAccessToken()
requestList.forEach((cb: any) => { requestList.forEach((cb: any) => {
cb() cb()
}) })
requestList = [] requestList = []
// TODO return new Promise((resolve) => {
console.info('刷新令牌end', res) resolve(this.axiosInstance(config))
// return new Promise((resolve) => { })
// resolve(this.axiosInstance(config))
// })
// res = await Promise.all([this.axiosInstance(config)])[0] // res = await Promise.all([this.axiosInstance(config)])[0]
} catch (e) { } catch (e) {
console.info(e) console.info(e)