diff --git a/apps/web/src/app/accounts/login/login-with-device.component.ts b/apps/web/src/app/accounts/login/login-with-device.component.ts index 3556f7d78e..fabc255220 100644 --- a/apps/web/src/app/accounts/login/login-with-device.component.ts +++ b/apps/web/src/app/accounts/login/login-with-device.component.ts @@ -12,6 +12,7 @@ import { CryptoFunctionService } from "@bitwarden/common/abstractions/cryptoFunc import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { LoginService } from "@bitwarden/common/abstractions/login.service"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { ValidationService } from "@bitwarden/common/abstractions/validation.service"; @@ -23,6 +24,8 @@ import { PasswordlessCreateAuthRequest } from "@bitwarden/common/models/request/ import { AuthRequestResponse } from "@bitwarden/common/models/response/auth-request.response"; import { ErrorResponse } from "@bitwarden/common/models/response/error.response"; +import { StateService } from "../../core/state/state.service"; + @Component({ selector: "app-login-with-device", templateUrl: "login-with-device.component.html", @@ -58,13 +61,15 @@ export class LoginWithDeviceComponent i18nService: I18nService, platformUtilsService: PlatformUtilsService, private anonymousHubService: AnonymousHubService, - private validationService: ValidationService + private validationService: ValidationService, + private stateService: StateService, + private loginService: LoginService ) { super(environmentService, i18nService, platformUtilsService); const navigation = this.router.getCurrentNavigation(); if (navigation) { - this.email = navigation.extras?.state?.email; + this.email = this.loginService.getEmail(); } //gets signalR push notification @@ -137,6 +142,7 @@ export class LoginWithDeviceComponent this.router.navigate([this.forcePasswordResetRoute]); } } else { + await this.setRememberEmailValues(); if (this.onSuccessfulLogin != null) { this.onSuccessfulLogin(); } @@ -196,4 +202,12 @@ export class LoginWithDeviceComponent localHashedPassword ); } + + private async setRememberEmailValues() { + const rememberEmail = this.loginService.getRememberEmail(); + const rememberedEmail = this.loginService.getEmail(); + await this.stateService.setRememberEmail(rememberEmail); + await this.stateService.setRememberedEmail(rememberEmail ? rememberedEmail : null); + this.loginService.clearValues(); + } } diff --git a/apps/web/src/app/accounts/login/login.component.ts b/apps/web/src/app/accounts/login/login.component.ts index 100e240c6b..a0867b1304 100644 --- a/apps/web/src/app/accounts/login/login.component.ts +++ b/apps/web/src/app/accounts/login/login.component.ts @@ -207,8 +207,8 @@ export class LoginComponent extends BaseLoginComponent implements OnInit, OnDest return; } - const email = this.formGroup.get("email").value; - this.router.navigate(["/login-with-device"], { state: { email: email } }); + this.setFormValues(); + this.router.navigate(["/login-with-device"]); } private getPasswordStrengthUserInput() {