[PM-4083] Fix case of misused promise (#6443)

* fix misused promise

* await resolution of totpService.getCode
This commit is contained in:
Jonathan Prusik 2023-10-09 10:29:50 -04:00 committed by GitHub
parent 320c1a5970
commit 3b803f62c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -148,7 +148,7 @@ export default class AutofillService implements AutofillServiceInterface {
throw new Error("Nothing to auto-fill."); throw new Error("Nothing to auto-fill.");
} }
let totpPromise: Promise<string> = null; let totp: string | null = null;
const canAccessPremium = await this.stateService.getCanAccessPremium(); const canAccessPremium = await this.stateService.getCanAccessPremium();
const defaultUriMatch = (await this.stateService.getDefaultUriMatch()) ?? UriMatchType.Domain; const defaultUriMatch = (await this.stateService.getDefaultUriMatch()) ?? UriMatchType.Domain;
@ -205,15 +205,14 @@ export default class AutofillService implements AutofillServiceInterface {
if ( if (
options.cipher.type !== CipherType.Login || options.cipher.type !== CipherType.Login ||
// eslint-disable-next-line @typescript-eslint/no-misused-promises totp !== null ||
totpPromise ||
!options.cipher.login.totp || !options.cipher.login.totp ||
(!canAccessPremium && !options.cipher.organizationUseTotp) (!canAccessPremium && !options.cipher.organizationUseTotp)
) { ) {
return; return;
} }
totpPromise = this.stateService.getDisableAutoTotpCopy().then((disabled) => { totp = await this.stateService.getDisableAutoTotpCopy().then((disabled) => {
if (!disabled) { if (!disabled) {
return this.totpService.getCode(options.cipher.login.totp); return this.totpService.getCode(options.cipher.login.totp);
} }
@ -224,8 +223,8 @@ export default class AutofillService implements AutofillServiceInterface {
if (didAutofill) { if (didAutofill) {
this.eventCollectionService.collect(EventType.Cipher_ClientAutofilled, options.cipher.id); this.eventCollectionService.collect(EventType.Cipher_ClientAutofilled, options.cipher.id);
if (totpPromise != null) { if (totp !== null) {
return await totpPromise; return totp;
} else { } else {
return null; return null;
} }