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();