1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-02 18:17:46 +01:00

Simplify validateEmail method

This commit is contained in:
Alec Rippberger 2024-10-21 08:38:55 -05:00
parent 8889ed3d3c
commit c9141a1cb5
No known key found for this signature in database
GPG Key ID: 9DD8DA583B28154A
2 changed files with 18 additions and 24 deletions

View File

@ -1,8 +1,7 @@
import { BehaviorSubject, Observable } from "rxjs";
import { AnonLayoutWrapperData, AnonLayoutWrapperDataService , DefaultAnonLayoutWrapperDataService } from "@bitwarden/auth/angular";
import { AnonLayoutWrapperData, AnonLayoutWrapperDataService } from "@bitwarden/auth/angular";
import { ExtensionAnonLayoutWrapperData } from "./extension-anon-layout-wrapper.component";
import { DefaultAnonLayoutWrapperDataService } from "@bitwarden/auth/angular";
export class ExtensionAnonLayoutWrapperDataService
extends DefaultAnonLayoutWrapperDataService

View File

@ -314,22 +314,9 @@ export class LoginComponent implements OnInit, OnDestroy {
await this.router.navigate(["/login-with-device"]);
}
protected async validateEmail(): Promise<void> {
protected async validateEmail(): Promise<boolean> {
this.formGroup.controls.email.markAsTouched();
const emailValid = this.formGroup.controls.email.valid;
if (emailValid) {
this.toggleLoginUiState(LoginUiState.MASTER_PASSWORD_ENTRY);
await this.getLoginWithDevice(this.emailFormControl.value);
this.anonLayoutWrapperDataService.setAnonLayoutWrapperData({
pageTitle: { key: "welcomeBack" },
pageSubtitle: this.emailFormControl.value,
pageIcon: this.Icons.WaveIcon,
});
this.loginComponentService.showBackButton(true);
}
return this.formGroup.controls.email.valid;
}
protected toggleLoginUiState(value: LoginUiState): void {
@ -394,19 +381,27 @@ export class LoginComponent implements OnInit, OnDestroy {
}
protected async continue(): Promise<void> {
await this.validateEmail();
if (await this.validateEmail()) {
this.toggleLoginUiState(LoginUiState.MASTER_PASSWORD_ENTRY);
await this.getLoginWithDevice(this.emailFormControl.value);
// TODO: Toast will be replaced with inline error message in PM-3301
if (!this.formGroup.controls.email.valid) {
this.anonLayoutWrapperDataService.setAnonLayoutWrapperData({
pageTitle: { key: "welcomeBack" },
pageSubtitle: this.emailFormControl.value,
pageIcon: this.Icons.WaveIcon,
});
this.loginComponentService.showBackButton(true);
this.focusInput();
} else {
// TODO: Toast will be replaced with inline error message in PM-3301
this.toastService.showToast({
variant: "error",
title: this.i18nService.t("errorOccured"),
message: this.i18nService.t("invalidEmail"),
});
return;
}
this.focusInput();
}
private async getLoginWithDevice(email: string): Promise<void> {