Clear active user if state has no users (#677)

* Clear active user if state has no users

* use the correct userId

* run prettier

* add null check
This commit is contained in:
Addison Beck 2022-02-11 15:11:31 -05:00 committed by GitHub
parent 3a1b5bf9a0
commit bcbb52e6ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 12 deletions

View File

@ -2376,26 +2376,24 @@ export class StateService<
protected async removeAccountFromLocalStorage(
userId: string = this.state.activeUserId
): Promise<void> {
const storedAccount = await this.storageService.get<TAccount>(userId, {
htmlStorageLocation: HtmlStorageLocation.Local,
});
await this.storageService.save(
userId,
const storedAccount = await this.getAccount(
this.reconcileOptions({ userId: userId }, await this.defaultOnDiskLocalOptions())
);
await this.saveAccount(
this.resetAccount(storedAccount),
await this.defaultOnDiskLocalOptions()
this.reconcileOptions({ userId: userId }, await this.defaultOnDiskLocalOptions())
);
}
protected async removeAccountFromSessionStorage(
userId: string = this.state.activeUserId
): Promise<void> {
const storedAccount = await this.storageService.get<TAccount>(userId, {
htmlStorageLocation: HtmlStorageLocation.Session,
});
await this.storageService.save(
userId,
const storedAccount = await this.getAccount(
this.reconcileOptions({ userId: userId }, await this.defaultOnDiskOptions())
);
await this.saveAccount(
this.resetAccount(storedAccount),
await this.defaultOnDiskOptions()
this.reconcileOptions({ userId: userId }, await this.defaultOnDiskOptions())
);
}
@ -2470,6 +2468,10 @@ export class StateService<
}
protected async dynamicallySetActiveUser() {
if (this.state.accounts == null || Object.keys(this.state.accounts).length < 1) {
await this.setActiveUser(null);
return;
}
for (const userId in this.state.accounts) {
if (userId == null) {
continue;