From 1e5e8e7dd53ded2eb37e6ec194fdda1cd2a103d9 Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Fri, 28 Apr 2023 11:37:11 +0200 Subject: [PATCH] [EC-598] fix: race condition when opening new popout --- .../services/fido2/browser-fido2-user-interface.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts b/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts index aafaa0d437..d014a4c070 100644 --- a/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts +++ b/apps/browser/src/services/fido2/browser-fido2-user-interface.service.ts @@ -311,11 +311,15 @@ export class BrowserFido2UserInterfaceSession implements Fido2UserInterfaceSessi } const queryParams = new URLSearchParams({ sessionId: this.sessionId }).toString(); + // create promise first to avoid race condition where the popout opens before we start listening + const connectPromise = firstValueFrom( + this.connected$.pipe(filter((connected) => connected === true)) + ); this.popout = await this.popupUtilsService.popOut( null, `popup/index.html?uilocation=popout#/fido2?${queryParams}`, { center: true } ); - await firstValueFrom(this.connected$.pipe(filter((connected) => connected === true))); + await connectPromise; } }