mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
update defaultOnInit()
This commit is contained in:
@@ -2,7 +2,7 @@ import { CommonModule } from "@angular/common";
|
|||||||
import { Component, ElementRef, Input, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
|
import { Component, ElementRef, Input, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
|
||||||
import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms";
|
import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms";
|
||||||
import { ActivatedRoute, Router, RouterModule } from "@angular/router";
|
import { ActivatedRoute, Router, RouterModule } from "@angular/router";
|
||||||
import { first, firstValueFrom, Subject, take, takeUntil } from "rxjs";
|
import { first, firstValueFrom, of, Subject, switchMap, take, takeUntil } from "rxjs";
|
||||||
|
|
||||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||||
import {
|
import {
|
||||||
@@ -346,22 +346,32 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
|
|||||||
private async defaultOnInit(): Promise<void> {
|
private async defaultOnInit(): Promise<void> {
|
||||||
let paramEmailIsSet = false;
|
let paramEmailIsSet = false;
|
||||||
|
|
||||||
this.activatedRoute.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
this.activatedRoute?.queryParams
|
||||||
if (!params) {
|
.pipe(
|
||||||
return;
|
switchMap((params) => {
|
||||||
}
|
if (!params) {
|
||||||
|
// If no params,loadEmailSettings from state
|
||||||
|
return this.loadEmailSettings();
|
||||||
|
}
|
||||||
|
|
||||||
const qParamsEmail = params.email;
|
const qParamsEmail = params.email;
|
||||||
|
|
||||||
// If there is an email in the query params, set that email as the form field value
|
// If there is an email in the query params, set that email as the form field value
|
||||||
if (qParamsEmail?.indexOf("@") > -1) {
|
if (qParamsEmail != null && qParamsEmail.indexOf("@") > -1) {
|
||||||
this.formGroup.controls.email.setValue(qParamsEmail);
|
this.formGroup.controls.email.setValue(qParamsEmail);
|
||||||
paramEmailIsSet = true;
|
paramEmailIsSet = true;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// If there is no email in the query params, attempt to load email settings from loginEmailService
|
// If there is no email in the query params, loadEmailSettings from state
|
||||||
if (!paramEmailIsSet) {
|
return paramEmailIsSet ? 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.activatedRoute) {
|
||||||
await this.loadEmailSettings();
|
await this.loadEmailSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user