Auth/PM-11635 - Extension Registration Bugfix - Unable to login after account creation issue (#10896)

* PM-11635 - Refactor Base Login Component NgOnInit to properly connect the loading of email settings from state to the processing of query params. If an email is not passed via query params (like registration / normal login), then we will try to load the email from state.

* PM-11635 - Extension login component - call parent ngOnInit as it is responsible for processing / setting email from either query params or state. The addition of the child ngOnInit prevented the parent component ngOnInit from executing.
This commit is contained in:
Jared Snider 2024-09-05 13:55:30 -04:00 committed by GitHub
parent 0902ca5ae8
commit 352ab29665
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 16 deletions

View File

@ -86,10 +86,8 @@ export class LoginComponent extends BaseLoginComponent implements OnInit {
} }
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
await super.ngOnInit();
if (this.showPasswordless) { 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(); await this.validateEmail();
} }
} }

View File

@ -1,8 +1,8 @@
import { Directive, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core"; import { Directive, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms"; import { FormBuilder, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { Subject, firstValueFrom } from "rxjs"; import { Subject, firstValueFrom, of } from "rxjs";
import { take, takeUntil } from "rxjs/operators"; import { switchMap, take, takeUntil } from "rxjs/operators";
import { import {
LoginStrategyServiceAbstraction, LoginStrategyServiceAbstraction,
@ -99,20 +99,31 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit,
} }
async ngOnInit() { async ngOnInit() {
this.route?.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => { this.route?.queryParams
if (!params) { .pipe(
return; 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) { if (queryParamsEmail != null && queryParamsEmail.indexOf("@") > -1) {
this.formGroup.controls.email.setValue(queryParamsEmail); this.formGroup.controls.email.setValue(queryParamsEmail);
this.paramEmailSet = true; 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(); await this.loadEmailSettings();
} }
} }