mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-30 22:41:33 +01:00
Prevent parallel refreshToken calls (#10799)
Co-authored-by: Todd Martin <106564991+trmartin4@users.noreply.github.com> Co-authored-by: Patrick-Pimentel-Bitwarden <ppimentel@bitwarden.com>
This commit is contained in:
parent
40606ee8af
commit
9a5ebf94a0
@ -158,6 +158,7 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
private deviceType: string;
|
private deviceType: string;
|
||||||
private isWebClient = false;
|
private isWebClient = false;
|
||||||
private isDesktopClient = false;
|
private isDesktopClient = false;
|
||||||
|
private refreshTokenPromise: Promise<string> | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message (responseJson.ErrorModel.Message) that comes back from the server when a new device verification is required.
|
* The message (responseJson.ErrorModel.Message) that comes back from the server when a new device verification is required.
|
||||||
@ -1733,7 +1734,18 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async refreshToken(): Promise<string> {
|
// Keep the running refreshTokenPromise to prevent parallel calls.
|
||||||
|
protected refreshToken(): Promise<string> {
|
||||||
|
if (this.refreshTokenPromise === undefined) {
|
||||||
|
this.refreshTokenPromise = this.internalRefreshToken();
|
||||||
|
void this.refreshTokenPromise.finally(() => {
|
||||||
|
this.refreshTokenPromise = undefined;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.refreshTokenPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async internalRefreshToken(): Promise<string> {
|
||||||
const refreshToken = await this.tokenService.getRefreshToken();
|
const refreshToken = await this.tokenService.getRefreshToken();
|
||||||
if (refreshToken != null && refreshToken !== "") {
|
if (refreshToken != null && refreshToken !== "") {
|
||||||
return this.refreshAccessToken();
|
return this.refreshAccessToken();
|
||||||
|
Loading…
Reference in New Issue
Block a user