diff --git a/apps/web/src/app/auth/login/login.component.ts b/apps/web/src/app/auth/login/login.component.ts index 0f2ceca878..890ef713a3 100644 --- a/apps/web/src/app/auth/login/login.component.ts +++ b/apps/web/src/app/auth/login/login.component.ts @@ -108,6 +108,7 @@ export class LoginComponent extends BaseLoginComponent implements OnInit { async ngOnInit() { // eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe this.route.queryParams.pipe(first()).subscribe(async (qParams) => { + // If there is an query parameter called 'org', set previousUrl to `/create-organization?org=paramValue` if (qParams.org != null) { const route = this.router.createUrlTree(["create-organization"], { queryParams: { plan: qParams.org }, @@ -115,7 +116,11 @@ export class LoginComponent extends BaseLoginComponent implements OnInit { this.routerService.setPreviousUrl(route.toString()); } - // Are they coming from an email for sponsoring a families organization + /** + * If there is a query parameter called 'sponsorshipToken', that means they are coming + * from an email for sponsoring a families organization. If so, then set the prevousUrl + * to `/setup/families-for-enterprise?token=paramValue` + */ if (qParams.sponsorshipToken != null) { const route = this.router.createUrlTree(["setup/families-for-enterprise"], { queryParams: { token: qParams.sponsorshipToken }, diff --git a/libs/angular/src/auth/components/login.component.ts b/libs/angular/src/auth/components/login.component.ts index f94ed8aaa8..fc8c69ce75 100644 --- a/libs/angular/src/auth/components/login.component.ts +++ b/libs/angular/src/auth/components/login.component.ts @@ -103,12 +103,14 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit, const queryParamsEmail = params.email; + // If there is an email in the query params, set that email as the form field value if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) { this.formGroup.controls.email.setValue(queryParamsEmail); this.paramEmailSet = true; } }); + // if there is no email in the query params, attempt to load email settings from loginEmailService if (!this.paramEmailSet) { await this.loadEmailSettings(); } diff --git a/libs/auth/src/angular/login/login.component.html b/libs/auth/src/angular/login/login.component.html index 27b11171b4..452cb2154c 100644 --- a/libs/auth/src/angular/login/login.component.html +++ b/libs/auth/src/angular/login/login.component.html @@ -1,5 +1,4 @@
-

New Component

diff --git a/libs/auth/src/angular/login/login.component.ts b/libs/auth/src/angular/login/login.component.ts index f69018a9aa..e907da001b 100644 --- a/libs/auth/src/angular/login/login.component.ts +++ b/libs/auth/src/angular/login/login.component.ts @@ -2,9 +2,10 @@ import { CommonModule } from "@angular/common"; import { Component, OnInit } from "@angular/core"; import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms"; import { ActivatedRoute, RouterModule } from "@angular/router"; -import { Subject, takeUntil } from "rxjs"; +import { firstValueFrom, Subject, takeUntil } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; +import { LoginEmailServiceAbstraction } from "@bitwarden/auth/common"; import { AsyncActionsModule, ButtonModule, @@ -27,8 +28,6 @@ import { ], }) export class LoginComponentV2 implements OnInit { - protected paramEmailSet = false; - protected formGroup = this.formBuilder.group({ email: ["", [Validators.required, Validators.email]], rememberEmail: [false], @@ -39,9 +38,12 @@ export class LoginComponentV2 implements OnInit { constructor( private activatedRoute: ActivatedRoute, private formBuilder: FormBuilder, + private loginEmailService: LoginEmailServiceAbstraction, ) {} async ngOnInit(): Promise { + let paramEmailIsSet = false; + this.activatedRoute.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => { if (!params) { return; @@ -51,12 +53,11 @@ export class LoginComponentV2 implements OnInit { if (qParamsEmail?.indexOf("@") > -1) { this.formGroup.controls.email.setValue(qParamsEmail); - - this.paramEmailSet = true; + paramEmailIsSet = true; } }); - if (!this.paramEmailSet) { + if (!paramEmailIsSet) { await this.loadEmailSettings(); } } @@ -65,5 +66,22 @@ export class LoginComponentV2 implements OnInit { async validateEmail() {} - private async loadEmailSettings() {} + private async loadEmailSettings() { + // Try to load the email from memory first + const email = this.loginEmailService.getEmail(); + const rememberEmail = this.loginEmailService.getRememberEmail(); + + if (email) { + this.formGroup.controls.email.setValue(email); + this.formGroup.controls.rememberEmail.setValue(rememberEmail); + } else { + // If there is no email in memory, check for a storedEmail on disk + const storedEmail = await firstValueFrom(this.loginEmailService.storedEmail$); + + if (storedEmail) { + this.formGroup.controls.email.setValue(storedEmail); + this.formGroup.controls.rememberEmail.setValue(true); // If there is a storedEmail, rememberEmail defaults to true + } + } + } }