mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-07 09:31:31 +01:00
Show master password error inline (#11740)
This commit is contained in:
parent
203a7b0c01
commit
a3375dd5b8
@ -18,7 +18,8 @@ import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstraction
|
|||||||
import { CaptchaIFrame } from "@bitwarden/common/auth/captcha-iframe";
|
import { CaptchaIFrame } from "@bitwarden/common/auth/captcha-iframe";
|
||||||
import { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
|
import { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
|
||||||
import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason";
|
import { ForceSetPasswordReason } from "@bitwarden/common/auth/models/domain/force-set-password-reason";
|
||||||
import { ClientType } from "@bitwarden/common/enums";
|
import { ClientType, HttpStatusCode } from "@bitwarden/common/enums";
|
||||||
|
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
|
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
|
||||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||||
@ -26,6 +27,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
|
|||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
|
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { SyncService } from "@bitwarden/common/platform/sync";
|
import { SyncService } from "@bitwarden/common/platform/sync";
|
||||||
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
||||||
@ -136,6 +138,7 @@ export class LoginComponent implements OnInit, OnDestroy {
|
|||||||
private syncService: SyncService,
|
private syncService: SyncService,
|
||||||
private toastService: ToastService,
|
private toastService: ToastService,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
|
private validationService: ValidationService,
|
||||||
) {
|
) {
|
||||||
this.clientType = this.platformUtilsService.getClientType();
|
this.clientType = this.platformUtilsService.getClientType();
|
||||||
this.loginViaAuthRequestSupported = this.loginComponentService.isLoginViaAuthRequestSupported();
|
this.loginViaAuthRequestSupported = this.loginComponentService.isLoginViaAuthRequestSupported();
|
||||||
@ -182,19 +185,54 @@ export class LoginComponent implements OnInit, OnDestroy {
|
|||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
||||||
const authResult = await this.loginStrategyService.logIn(credentials);
|
try {
|
||||||
|
const authResult = await this.loginStrategyService.logIn(credentials);
|
||||||
|
|
||||||
await this.saveEmailSettings();
|
await this.saveEmailSettings();
|
||||||
await this.handleAuthResult(authResult);
|
await this.handleAuthResult(authResult);
|
||||||
|
|
||||||
if (this.clientType === ClientType.Desktop) {
|
if (this.clientType === ClientType.Desktop) {
|
||||||
if (this.captchaSiteKey) {
|
if (this.captchaSiteKey) {
|
||||||
const content = document.getElementById("content") as HTMLDivElement;
|
const content = document.getElementById("content") as HTMLDivElement;
|
||||||
content.setAttribute("style", "width:335px");
|
content.setAttribute("style", "width:335px");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logService.error(error);
|
||||||
|
this.handleSubmitError(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the error from the submit function.
|
||||||
|
*
|
||||||
|
* @param error The error object.
|
||||||
|
*/
|
||||||
|
private handleSubmitError(error: unknown) {
|
||||||
|
// Handle error responses
|
||||||
|
if (error instanceof ErrorResponse) {
|
||||||
|
switch (error.statusCode) {
|
||||||
|
case HttpStatusCode.BadRequest: {
|
||||||
|
if (error.message.toLowerCase().includes("username or password is incorrect")) {
|
||||||
|
this.formGroup.controls.masterPassword.setErrors({
|
||||||
|
error: {
|
||||||
|
message: this.i18nService.t("invalidMasterPassword"),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
// Allow all other errors to be handled by toast
|
||||||
|
this.validationService.showError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Allow all other errors to be handled by toast
|
||||||
|
this.validationService.showError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the result of the authentication process.
|
* Handles the result of the authentication process.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user