mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 05:43:41 +00:00
fix(auth-request): [PM-24376] - Fixed bad logic for selecting which email to use to log in with. (#15875)
This commit is contained in:
committed by
GitHub
parent
25ae1f1aa7
commit
0bd48f6e58
@@ -2,7 +2,7 @@ import { CommonModule } from "@angular/common";
|
|||||||
import { Component, OnDestroy, OnInit } from "@angular/core";
|
import { Component, OnDestroy, OnInit } from "@angular/core";
|
||||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||||
import { IsActiveMatchOptions, Router, RouterModule } from "@angular/router";
|
import { IsActiveMatchOptions, Router, RouterModule } from "@angular/router";
|
||||||
import { Observable, filter, firstValueFrom, map, merge, race, take, timer } from "rxjs";
|
import { Observable, firstValueFrom, map } from "rxjs";
|
||||||
|
|
||||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||||
import {
|
import {
|
||||||
@@ -185,17 +185,15 @@ export class LoginViaAuthRequestComponent implements OnInit, OnDestroy {
|
|||||||
this.accountService.activeAccount$.pipe(map((a) => a?.email));
|
this.accountService.activeAccount$.pipe(map((a) => a?.email));
|
||||||
const loginEmail$: Observable<string | null> = this.loginEmailService.loginEmail$;
|
const loginEmail$: Observable<string | null> = this.loginEmailService.loginEmail$;
|
||||||
|
|
||||||
// Use merge as we want to get the first value from either observable.
|
let loginEmail: string | undefined = (await firstValueFrom(loginEmail$)) ?? undefined;
|
||||||
const firstEmail$ = merge(loginEmail$, activeAccountEmail$).pipe(
|
|
||||||
filter((e): e is string => !!e), // convert null/undefined to false and filter out so we narrow type to string
|
|
||||||
take(1), // complete after first value
|
|
||||||
);
|
|
||||||
|
|
||||||
const emailRetrievalTimeout$ = timer(2500).pipe(map(() => undefined as undefined));
|
if (!loginEmail) {
|
||||||
|
loginEmail = (await firstValueFrom(activeAccountEmail$)) ?? undefined;
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for either the first email or the timeout to occur so we can proceed
|
// Wait for either the first email or the timeout to occur so we can proceed
|
||||||
// neither above observable will complete, so we have to add a timeout
|
// neither above observable will complete, so we have to add a timeout
|
||||||
this.email = await firstValueFrom(race(firstEmail$, emailRetrievalTimeout$));
|
this.email = loginEmail;
|
||||||
|
|
||||||
if (!this.email) {
|
if (!this.email) {
|
||||||
await this.handleMissingEmail();
|
await this.handleMissingEmail();
|
||||||
|
|||||||
Reference in New Issue
Block a user