From bcbb52e6ec007b9bafd09fab5253bd3f015e694f Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Fri, 11 Feb 2022 15:11:31 -0500 Subject: [PATCH] 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 --- common/src/services/state.service.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 23c77a84..9ae48427 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -2376,26 +2376,24 @@ export class StateService< protected async removeAccountFromLocalStorage( userId: string = this.state.activeUserId ): Promise { - const storedAccount = await this.storageService.get(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 { - const storedAccount = await this.storageService.get(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;