From 7d29b3be13974e0bb620c121119fe23f065889ad Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Fri, 17 May 2024 14:47:21 -0400 Subject: [PATCH] Wait for account to switch before proceeding (#9229) --- apps/browser/src/background/main.background.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index e77203f83e..ae5f5bf589 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1214,7 +1214,22 @@ export default class MainBackground { ); // can be removed once password generation history is migrated to state providers await this.stateService.clearDecryptedData(currentlyActiveAccount); + // HACK to ensure account is switched before proceeding + const switchPromise = firstValueFrom( + this.accountService.activeAccount$.pipe( + filter((account) => (account?.id ?? null) === (userId ?? null)), + timeout({ + first: 1_000, + with: () => { + throw new Error( + "The account switch process did not complete in a reasonable amount of time.", + ); + }, + }), + ), + ); await this.accountService.switchAccount(userId); + await switchPromise; // Clear sequentialized caches clearCaches();