Trust our own copy of authenticatedAccounts until all accounts are initialized (#8888)

This commit is contained in:
Justin Baur 2024-04-23 16:57:19 -04:00 committed by GitHub
parent 790c9a6141
commit 8ef5340635
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 6 deletions

View File

@ -115,14 +115,19 @@ export class StateService<
return;
}
// Get all likely authenticated accounts
const authenticatedAccounts = (
(await this.storageService.get<string[]>(keys.authenticatedAccounts)) ?? []
).filter((account) => account != null);
await this.updateState(async (state) => {
state.authenticatedAccounts =
(await this.storageService.get<string[]>(keys.authenticatedAccounts)) ?? [];
for (const i in state.authenticatedAccounts) {
if (i != null) {
state = await this.syncAccountFromDisk(state.authenticatedAccounts[i]);
}
for (const i in authenticatedAccounts) {
state = await this.syncAccountFromDisk(authenticatedAccounts[i]);
}
// After all individual accounts have been added
state.authenticatedAccounts = authenticatedAccounts;
const storedActiveUser = await this.storageService.get<string>(keys.activeUserId);
if (storedActiveUser != null) {
state.activeUserId = storedActiveUser;