File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ export class RefreshScheme<
5454{
5555 public refreshToken : RefreshToken
5656 public refreshController : RefreshController
57+ public refreshRequest : Promise < HTTPResponse > | null = null
5758
5859 constructor (
5960 $auth : Auth ,
@@ -174,9 +175,15 @@ export class RefreshScheme<
174175
175176 cleanObj ( endpoint . data )
176177
177- // Make refresh request
178- return this . $auth
179- . request ( endpoint , this . options . endpoints . refresh )
178+ // When calling refreshTokens() multiple times (parallel axios request)
179+ // Use the same promise as the first refresh request
180+ // or making a refresh request if does not exist
181+ // instead of making parallel refresh request
182+ this . refreshRequest =
183+ this . refreshRequest ||
184+ this . $auth . request ( endpoint , this . options . endpoints . refresh )
185+
186+ return this . refreshRequest
180187 . then ( ( response ) => {
181188 // Update tokens
182189 this . updateTokens ( response , { isRefreshing : true } )
@@ -186,6 +193,10 @@ export class RefreshScheme<
186193 this . $auth . callOnError ( error , { method : 'refreshToken' } )
187194 return Promise . reject ( error )
188195 } )
196+ . finally ( ( ) => {
197+ // Reset the refresh request
198+ this . refreshRequest = null
199+ } )
189200 }
190201
191202 setUserToken (
You can’t perform that action at this time.
0 commit comments