diff --git a/libs/auth/src/angular/login-via-auth-request/login-via-auth-request.component.ts b/libs/auth/src/angular/login-via-auth-request/login-via-auth-request.component.ts index 5e410c538f0..10b19567946 100644 --- a/libs/auth/src/angular/login-via-auth-request/login-via-auth-request.component.ts +++ b/libs/auth/src/angular/login-via-auth-request/login-via-auth-request.component.ts @@ -2,7 +2,7 @@ import { CommonModule } from "@angular/common"; import { Component, OnDestroy, OnInit } from "@angular/core"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; 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 { @@ -185,17 +185,15 @@ export class LoginViaAuthRequestComponent implements OnInit, OnDestroy { this.accountService.activeAccount$.pipe(map((a) => a?.email)); const loginEmail$: Observable = this.loginEmailService.loginEmail$; - // Use merge as we want to get the first value from either observable. - 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 - ); + let loginEmail: string | undefined = (await firstValueFrom(loginEmail$)) ?? undefined; - 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 // 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) { await this.handleMissingEmail();