1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

Wait for account to switch before proceeding (#9229)

This commit is contained in:
Matt Gibson 2024-05-17 14:47:21 -04:00 committed by GitHub
parent f97064effe
commit 7d29b3be13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1214,7 +1214,22 @@ export default class MainBackground {
); );
// can be removed once password generation history is migrated to state providers // can be removed once password generation history is migrated to state providers
await this.stateService.clearDecryptedData(currentlyActiveAccount); 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 this.accountService.switchAccount(userId);
await switchPromise;
// Clear sequentialized caches // Clear sequentialized caches
clearCaches(); clearCaches();