From 907cb6b4ad5deda3f7ecedf0252134683b6bdd43 Mon Sep 17 00:00:00 2001 From: addison Date: Mon, 22 Nov 2021 10:05:09 -0500 Subject: [PATCH] [bug] Update correct storage locations on account removal --- common/src/services/state.service.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 6ef52ec2..7056a287 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -53,7 +53,7 @@ export class StateService implements StateServiceAbstraction { if (await this.getActiveUserIdFromStorage() != null) { const diskState = await this.storageService.get('state', await this.defaultOnDiskOptions()); this.state = diskState; - await this.storageService.save('state', diskState, await this.defaultOnDiskMemoryOptions()); + await this.saveStateToStorage(diskState, await this.defaultOnDiskMemoryOptions()); } } @@ -70,7 +70,7 @@ export class StateService implements StateServiceAbstraction { this.state.activeUserId = userId; const storedState = await this.storageService.get('state', await this.defaultOnDiskOptions()); storedState.activeUserId = userId; - await this.storageService.save('state', storedState, await this.defaultOnDiskOptions()); + await this.saveStateToStorage(storedState, await this.defaultOnDiskOptions()); await this.pushAccounts(); } @@ -1200,7 +1200,7 @@ export class StateService implements StateServiceAbstraction { } else { const state = await this.storageService.get('state', options) ?? new State(); state.globals = globals; - await this.storageService.save('state', state, options); + await this.saveStateToStorage(state, options); } } @@ -1304,7 +1304,7 @@ export class StateService implements StateServiceAbstraction { account = storedAccount; } storedState.accounts[account.profile.userId] = account; - await this.storageService.save('state', storedState, await this.defaultOnDiskLocalOptions()); + await this.saveStateToStorage(storedState, await this.defaultOnDiskLocalOptions()); } private async scaffoldNewAccountMemoryStorage(account: Account): Promise { @@ -1316,7 +1316,7 @@ export class StateService implements StateServiceAbstraction { account = storedAccount; } storedState.accounts[account.profile.userId] = account; - await this.storageService.save('state', storedState, await this.defaultOnDiskMemoryOptions()); + await this.saveStateToStorage(storedState, await this.defaultOnDiskMemoryOptions()); } private async scaffoldNewAccountSessionStorage(account: Account): Promise { @@ -1328,7 +1328,7 @@ export class StateService implements StateServiceAbstraction { account = storedAccount; } storedState.accounts[account.profile.userId] = account; - await this.storageService.save('state', storedState, await this.defaultOnDiskOptions()); + await this.saveStateToStorage(storedState, await this.defaultOnDiskOptions()); } private async scaffoldNewAccountSecureStorage(account: Account): Promise { @@ -1422,7 +1422,7 @@ export class StateService implements StateServiceAbstraction { } private async removeAccountFromLocalStorage(userId: string = this.state.activeUserId): Promise { - const state = await this.secureStorageService.get('state', { htmlStorageLocation: HtmlStorageLocation.Local }); + const state = await this.storageService.get('state', { htmlStorageLocation: HtmlStorageLocation.Local }); if (state?.accounts[userId] == null) { return; } @@ -1433,11 +1433,11 @@ export class StateService implements StateServiceAbstraction { data: state.accounts[userId].data, }); - await this.storageService.save('state', state, { htmlStorageLocation: HtmlStorageLocation.Local }); + await this.saveStateToStorage(state, await this.defaultOnDiskLocalOptions()); } private async removeAccountFromSessionStorage(userId: string = this.state.activeUserId): Promise { - const state = await this.secureStorageService.get('state', { htmlStorageLocation: HtmlStorageLocation.Session }); + const state = await this.storageService.get('state', { htmlStorageLocation: HtmlStorageLocation.Session }); if (state?.accounts[userId] == null) { return; } @@ -1448,7 +1448,7 @@ export class StateService implements StateServiceAbstraction { data: state.accounts[userId].data, }); - await this.storageService.save('state', state, { htmlStorageLocation: HtmlStorageLocation.Session }); + await this.saveStateToStorage(state, await this.defaultOnDiskOptions()); } private async removeAccountFromSecureStorage(userId: string = this.state.activeUserId): Promise { @@ -1466,4 +1466,8 @@ export class StateService implements StateServiceAbstraction { } delete this.state.accounts[userId ?? this.state.activeUserId]; } + + private async saveStateToStorage(state: State, options: StorageOptions): Promise { + await this.storageService.save('state', state, options); + } }