diff --git a/apps/browser/src/auth/popup/login.component.ts b/apps/browser/src/auth/popup/login.component.ts index 09bfdbbc24..ea72fb61f5 100644 --- a/apps/browser/src/auth/popup/login.component.ts +++ b/apps/browser/src/auth/popup/login.component.ts @@ -86,10 +86,8 @@ export class LoginComponent extends BaseLoginComponent implements OnInit { } async ngOnInit(): Promise { + await super.ngOnInit(); if (this.showPasswordless) { - const loginEmail = await firstValueFrom(this.loginEmailService.loginEmail$); - this.formGroup.controls.email.setValue(loginEmail); - this.formGroup.controls.rememberEmail.setValue(this.loginEmailService.getRememberEmail()); await this.validateEmail(); } } diff --git a/libs/angular/src/auth/components/login.component.ts b/libs/angular/src/auth/components/login.component.ts index 3b927a0571..b798a8df0b 100644 --- a/libs/angular/src/auth/components/login.component.ts +++ b/libs/angular/src/auth/components/login.component.ts @@ -1,8 +1,8 @@ import { Directive, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core"; import { FormBuilder, Validators } from "@angular/forms"; import { ActivatedRoute, Router } from "@angular/router"; -import { Subject, firstValueFrom } from "rxjs"; -import { take, takeUntil } from "rxjs/operators"; +import { Subject, firstValueFrom, of } from "rxjs"; +import { switchMap, take, takeUntil } from "rxjs/operators"; import { LoginStrategyServiceAbstraction, @@ -99,20 +99,31 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit, } async ngOnInit() { - this.route?.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => { - if (!params) { - return; - } + this.route?.queryParams + .pipe( + switchMap((params) => { + if (!params) { + // If no params,loadEmailSettings from state + return this.loadEmailSettings(); + } - const queryParamsEmail = params.email; + const queryParamsEmail = params.email; - if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) { - this.formGroup.controls.email.setValue(queryParamsEmail); - this.paramEmailSet = true; - } - }); + if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) { + this.formGroup.controls.email.setValue(queryParamsEmail); + this.paramEmailSet = true; + } - if (!this.paramEmailSet) { + // If paramEmailSet is false, loadEmailSettings from state + return this.paramEmailSet ? of(null) : this.loadEmailSettings(); + }), + takeUntil(this.destroy$), + ) + .subscribe(); + + // Backup check to handle unknown case where activatedRoute is not available + // This shouldn't happen under normal circumstances + if (!this.route) { await this.loadEmailSettings(); } }