-
Notifications
You must be signed in to change notification settings - Fork 913
Open
Labels
Description
Version
module: "5.0.0-1643791578.532b3d6"
nuxt: ^2.15.7
Nuxt configuration
mode:
- universal
- spa
Nuxt configuration
Reproduction
- in the cookie, update token expiry to 1 (making the token expired)
- Run axios request on parallel
What is expected?
- RequestToken is only run once
What is actually happening?
- Refresh Token runs twice
Additional information
I have separate axios instance for calling API other than auth0
const internalAxios = $axios.create()
internalAxios.onRequest(async (config: AxiosRequestConfig): Promise<AxiosRequestConfig> => {
const auth0Strategy = app.$auth.strategy as Auth0Scheme
if (!auth0Strategy.token.status().valid()) {
if (auth0Strategy.refreshToken.status().valid()) {
await app.$auth.refreshTokens()
} else {
app.$auth.reset()
app.$auth.loginWith('auth0')
}
}
config.headers.authorization = decodeURI(auth0Strategy.token.get() as string)
return config
})
Calling refreshToken via $auth will call the refresh Token only once
On further investigation calling refreshToken via $auth will trigger
Lines 266 to 279 in c9880dc
refreshTokens(): Promise<HTTPResponse | void> { | |
if (!(this.getStrategy() as RefreshableScheme).refreshController) { | |
return Promise.resolve() | |
} | |
return Promise.resolve( | |
( | |
this.getStrategy() as RefreshableScheme | |
).refreshController.handleRefresh() | |
).catch((error) => { | |
this.callOnError(error, { method: 'refreshTokens' }) | |
return Promise.reject(error) | |
}) | |
} |
auth-module/src/inc/refresh-controller.ts
Lines 13 to 20 in c9880dc
handleRefresh(): Promise<HTTPResponse | void> { | |
// Another request has started refreshing the token, wait for it to complete | |
if (this._refreshPromise) { | |
return this._refreshPromise | |
} | |
return this._doRefresh() | |
} |
But the interceptor will call this in which it doesnt check whether refresh Token is still ongoing or not
auth-module/src/inc/request-handler.ts
Lines 61 to 68 in c9880dc
isValid = await (this.scheme as RefreshableScheme) | |
.refreshTokens() | |
.then(() => true) | |
.catch(() => { | |
// Tokens couldn't be refreshed. Force reset. | |
this.scheme.reset() | |
throw new ExpiredAuthSessionError() | |
}) |
auth-module/src/schemes/oauth2.ts
Line 433 in c9880dc
async refreshTokens(): Promise<HTTPResponse | void> { |
Checklist
- I have tested with the latest Nuxt version and the issue still occurs
- I have tested with the latest module version and the issue still occurs
- I have searched the issue tracker and this issue hasn't been reported yet