From b0dadca574f7860915b6c26f5a843826e8fbdce0 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Thu, 24 Aug 2023 15:45:17 -0400 Subject: [PATCH] Merged branch with master and fixed conflicts --- .../src/auth/popup/two-factor.component.ts | 11 ++++++++++ .../src/platform/browser/browser-api.ts | 21 ++++++++----------- .../popup/components/fido2/fido2.component.ts | 8 +++---- .../auth/components/two-factor.component.ts | 8 ------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/apps/browser/src/auth/popup/two-factor.component.ts b/apps/browser/src/auth/popup/two-factor.component.ts index c0af31d25e..c44b22ab31 100644 --- a/apps/browser/src/auth/popup/two-factor.component.ts +++ b/apps/browser/src/auth/popup/two-factor.component.ts @@ -32,6 +32,7 @@ const BroadcasterSubscriptionId = "TwoFactorComponent"; }) export class TwoFactorComponent extends BaseTwoFactorComponent { showNewWindowMessage = false; + redirectUrl: string; constructor( authService: AuthService, @@ -74,6 +75,16 @@ export class TwoFactorComponent extends BaseTwoFactorComponent { syncService.fullSync(true); }; + super.onSuccessfulLoginNavigate = async () => { + // The `redirectUrl` parameter determines the target route after a successful login. + // If provided in the URL's query parameters, the user will be redirected + // to the specified path once they are authenticated. + if (this.route.snapshot.queryParams.redirectUrl) { + this.redirectUrl = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl); + this.router.navigateByUrl(this.redirectUrl); + } + }; + super.onSuccessfulLoginTde = async () => { syncService.fullSync(true); }; diff --git a/apps/browser/src/platform/browser/browser-api.ts b/apps/browser/src/platform/browser/browser-api.ts index 391f883030..a89f46253e 100644 --- a/apps/browser/src/platform/browser/browser-api.ts +++ b/apps/browser/src/platform/browser/browser-api.ts @@ -1,4 +1,3 @@ -import type { NgZone } from "@angular/core"; import { Observable } from "rxjs"; import { DeviceType } from "@bitwarden/common/enums"; @@ -245,22 +244,20 @@ export class BrowserApi { } /** - * Creates an observable that listens for messages. If an Angular zone is provided, - * ensures that the message processing runs within that zone, triggering change detection. + * Creates an observable that listens for messages. While this observable might + * operate outside the Angular zone, it's recommended to pipe it with the + * utility function `runInsideAngular` to ensure proper triggering of change detection + * and other zone-related behaviors. + * + * @see /libs/angular/src/utils/run-inside-angular.operator.ts + * * This solution was devised to address an issue in the `Fido2Component`, where the * original message listener operated outside the Angular zone. - * - * @param {NgZone} [zone] - An optional Angular zone to ensure UI updates and change - * detection are triggered. If omitted, operates outside the Angular zone. */ - static messageListener$(zone?: NgZone) { + static messageListener$() { return new Observable((subscriber) => { const handler = (message: unknown) => { - if (zone) { - zone.run(() => subscriber.next(message)); - } else { - subscriber.next(message); - } + subscriber.next(message); }; chrome.runtime.onMessage.addListener(handler); return () => chrome.runtime.onMessage.removeListener(handler); diff --git a/apps/browser/src/vault/popup/components/fido2/fido2.component.ts b/apps/browser/src/vault/popup/components/fido2/fido2.component.ts index d5f3030417..4aaba3b063 100644 --- a/apps/browser/src/vault/popup/components/fido2/fido2.component.ts +++ b/apps/browser/src/vault/popup/components/fido2/fido2.component.ts @@ -12,6 +12,7 @@ import { takeUntil, } from "rxjs"; +import { runInsideAngular } from "@bitwarden/angular/utils/run-inside-angular.operator"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { PasswordRepromptService } from "@bitwarden/common/vault/abstractions/password-reprompt.service"; import { CipherType } from "@bitwarden/common/vault/enums/cipher-type"; @@ -58,11 +59,8 @@ export class Fido2Component implements OnInit, OnDestroy { map((queryParamMap) => queryParamMap.get("sessionId")) ); - combineLatest([ - sessionId$, - BrowserApi.messageListener$(this.ngZone) as Observable, - ]) - .pipe(takeUntil(this.destroy$)) + combineLatest([sessionId$, BrowserApi.messageListener$() as Observable]) + .pipe(runInsideAngular(this.ngZone), takeUntil(this.destroy$)) .subscribe(([sessionId, message]) => { this.sessionId = sessionId; if (message.type === "NewSessionCreatedRequest" && message.sessionId !== sessionId) { diff --git a/libs/angular/src/auth/components/two-factor.component.ts b/libs/angular/src/auth/components/two-factor.component.ts index 0f4e6e2421..0a06d39315 100644 --- a/libs/angular/src/auth/components/two-factor.component.ts +++ b/libs/angular/src/auth/components/two-factor.component.ts @@ -45,7 +45,6 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI formPromise: Promise; emailPromise: Promise; orgIdentifier: string = null; - redirectUrl: string; onSuccessfulLogin: () => Promise; onSuccessfulLoginNavigate: () => Promise; @@ -207,13 +206,6 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI } async doSubmit() { - // The `redirectUrl` parameter determines the target route after a successful login. - // If provided in the URL's query parameters, the user will be redirected - // to the specified path once they are authenticated. - if (this.route.snapshot.queryParams.redirectUrl) { - this.successRoute = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl); - } - this.formPromise = this.authService.logInTwoFactor( new TokenTwoFactorRequest(this.selectedProviderType, this.token, this.remember), this.captchaToken