mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-29 22:31:29 +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 isWebClient = 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.
|
||||
@ -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();
|
||||
if (refreshToken != null && refreshToken !== "") {
|
||||
return this.refreshAccessToken();
|
||||
|
Loading…
Reference in New Issue
Block a user