1
0
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:
Timshel 2025-01-24 20:23:22 +01:00 committed by GitHub
parent 40606ee8af
commit 9a5ebf94a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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();