Skip to content

Commit

Permalink
PM-5242 - UserVerificationDialogComp - Refactor submit logic to handl…
Browse files Browse the repository at this point in the history
…e different return methodologies in existing MP and OTP user verification service code vs new PIN flow (e.g., throwing an error instead of returning false)
  • Loading branch information
JaredSnider-Bitwarden committed Jan 18, 2024
1 parent 03284ba commit 3a304d3
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,36 @@ export class UserVerificationDialogComponent {
}

try {
//Incorrect secret will throw an invalid password error.
await this.userVerificationService.verifyUser(this.secret.value);
this.invalidSecret = false;
// TODO: once we migrate all user verification scenarios to use this new implementation,
// we should consider refactoring the user verification service handling of the
// OTP and MP flows to not throw errors on verification failure.
const verificationResult = await this.userVerificationService.verifyUser(this.secret.value);

if (verificationResult) {
this.invalidSecret = false;
this.close({
userAction: "confirm",
verificationSuccess: true,
noAvailableClientVerificationMethods: false,
});
} else {
this.invalidSecret = true;

// Only pin should ever get here, but added this check to be safe.
if (this.activeClientVerificationOption === this.ActiveClientVerificationOption.Pin) {
this.platformUtilsService.showToast(
"error",
this.i18nService.t("error"),
this.i18nService.t("invalidPin"),
);
}
}
} catch (e) {
// Catch handles OTP and MP verification scenarios as those throw errors on verification failure instead of returning false like PIN and biometrics.
this.invalidSecret = true;
this.platformUtilsService.showToast("error", this.i18nService.t("error"), e.message);
return;
}

this.close({
userAction: "confirm",
verificationSuccess: true,
noAvailableClientVerificationMethods: false,
});
};

cancel() {
Expand Down

0 comments on commit 3a304d3

Please sign in to comment.