From beb930902a3b5975eebc952f65a6c51159e79074 Mon Sep 17 00:00:00 2001 From: KiruthigaManivannan <162679756+KiruthigaManivannan@users.noreply.github.com> Date: Wed, 29 May 2024 19:33:28 +0530 Subject: [PATCH] PM-8337 Add Invalid Secret Handling to Two Factor Verify Dialog (#9325) --- .../settings/two-factor-verify.component.html | 2 +- .../settings/two-factor-verify.component.ts | 41 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/apps/web/src/app/auth/settings/two-factor-verify.component.html b/apps/web/src/app/auth/settings/two-factor-verify.component.html index 283282ccb8..288a096c23 100644 --- a/apps/web/src/app/auth/settings/two-factor-verify.component.html +++ b/apps/web/src/app/auth/settings/two-factor-verify.component.html @@ -7,8 +7,8 @@ diff --git a/apps/web/src/app/auth/settings/two-factor-verify.component.ts b/apps/web/src/app/auth/settings/two-factor-verify.component.ts index 7dc2847b82..d41efc9b02 100644 --- a/apps/web/src/app/auth/settings/two-factor-verify.component.ts +++ b/apps/web/src/app/auth/settings/two-factor-verify.component.ts @@ -10,6 +10,7 @@ import { SecretVerificationRequest } from "@bitwarden/common/auth/models/request import { AuthResponse } from "@bitwarden/common/auth/types/auth-response"; import { TwoFactorResponse } from "@bitwarden/common/auth/types/two-factor-response"; import { Verification } from "@bitwarden/common/auth/types/verification"; +import { ErrorResponse } from "@bitwarden/common/models/response/error.response"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { DialogService } from "@bitwarden/components"; @@ -32,6 +33,7 @@ export class TwoFactorVerifyComponent { protected formGroup = new FormGroup({ secret: new FormControl(null), }); + invalidSecret: boolean = false; constructor( @Inject(DIALOG_DATA) protected data: TwoFactorVerifyDialogData, @@ -45,23 +47,30 @@ export class TwoFactorVerifyComponent { } submit = async () => { - let hashedSecret: string; - this.formPromise = this.userVerificationService - .buildRequest(this.formGroup.value.secret) - .then((request) => { - hashedSecret = - this.formGroup.value.secret.type === VerificationType.MasterPassword - ? request.masterPasswordHash - : request.otp; - return this.apiCall(request); - }); + try { + let hashedSecret: string; + this.formPromise = this.userVerificationService + .buildRequest(this.formGroup.value.secret) + .then((request) => { + hashedSecret = + this.formGroup.value.secret.type === VerificationType.MasterPassword + ? request.masterPasswordHash + : request.otp; + return this.apiCall(request); + }); - const response = await this.formPromise; - this.dialogRef.close({ - response: response, - secret: hashedSecret, - verificationType: this.formGroup.value.secret.type, - }); + const response = await this.formPromise; + this.dialogRef.close({ + response: response, + secret: hashedSecret, + verificationType: this.formGroup.value.secret.type, + }); + } catch (e) { + if (e instanceof ErrorResponse && e.statusCode === 400) { + this.invalidSecret = true; + } + throw e; + } }; get dialogTitle(): string {