mirror of
https://github.com/bitwarden/browser.git
synced 2024-08-27 23:31:41 +02:00
PM-8337 Add Invalid Secret Handling to Two Factor Verify Dialog (#9325)
This commit is contained in:
parent
9d342f61cb
commit
beb930902a
|
@ -7,8 +7,8 @@
|
||||||
<ng-container bitDialogContent>
|
<ng-container bitDialogContent>
|
||||||
<app-user-verification-form-input
|
<app-user-verification-form-input
|
||||||
formControlName="secret"
|
formControlName="secret"
|
||||||
ngDefaultControl
|
|
||||||
name="secret"
|
name="secret"
|
||||||
|
[(invalidSecret)]="invalidSecret"
|
||||||
></app-user-verification-form-input>
|
></app-user-verification-form-input>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container bitDialogFooter>
|
<ng-container bitDialogFooter>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { SecretVerificationRequest } from "@bitwarden/common/auth/models/request
|
||||||
import { AuthResponse } from "@bitwarden/common/auth/types/auth-response";
|
import { AuthResponse } from "@bitwarden/common/auth/types/auth-response";
|
||||||
import { TwoFactorResponse } from "@bitwarden/common/auth/types/two-factor-response";
|
import { TwoFactorResponse } from "@bitwarden/common/auth/types/two-factor-response";
|
||||||
import { Verification } from "@bitwarden/common/auth/types/verification";
|
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 { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { DialogService } from "@bitwarden/components";
|
import { DialogService } from "@bitwarden/components";
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ export class TwoFactorVerifyComponent {
|
||||||
protected formGroup = new FormGroup({
|
protected formGroup = new FormGroup({
|
||||||
secret: new FormControl<Verification | null>(null),
|
secret: new FormControl<Verification | null>(null),
|
||||||
});
|
});
|
||||||
|
invalidSecret: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DIALOG_DATA) protected data: TwoFactorVerifyDialogData,
|
@Inject(DIALOG_DATA) protected data: TwoFactorVerifyDialogData,
|
||||||
|
@ -45,23 +47,30 @@ export class TwoFactorVerifyComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
submit = async () => {
|
submit = async () => {
|
||||||
let hashedSecret: string;
|
try {
|
||||||
this.formPromise = this.userVerificationService
|
let hashedSecret: string;
|
||||||
.buildRequest(this.formGroup.value.secret)
|
this.formPromise = this.userVerificationService
|
||||||
.then((request) => {
|
.buildRequest(this.formGroup.value.secret)
|
||||||
hashedSecret =
|
.then((request) => {
|
||||||
this.formGroup.value.secret.type === VerificationType.MasterPassword
|
hashedSecret =
|
||||||
? request.masterPasswordHash
|
this.formGroup.value.secret.type === VerificationType.MasterPassword
|
||||||
: request.otp;
|
? request.masterPasswordHash
|
||||||
return this.apiCall(request);
|
: request.otp;
|
||||||
});
|
return this.apiCall(request);
|
||||||
|
});
|
||||||
|
|
||||||
const response = await this.formPromise;
|
const response = await this.formPromise;
|
||||||
this.dialogRef.close({
|
this.dialogRef.close({
|
||||||
response: response,
|
response: response,
|
||||||
secret: hashedSecret,
|
secret: hashedSecret,
|
||||||
verificationType: this.formGroup.value.secret.type,
|
verificationType: this.formGroup.value.secret.type,
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof ErrorResponse && e.statusCode === 400) {
|
||||||
|
this.invalidSecret = true;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
get dialogTitle(): string {
|
get dialogTitle(): string {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user