diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index c663f12d..965b7c5d 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -78,9 +78,10 @@ export class StateService implements StateServiceAbstraction { } async clean(options?: StorageOptions): Promise { - await this.secureStorageService.remove(options?.userId ?? this.state.activeUserId); - await this.storageService.remove(options?.userId ?? this.state.activeUserId); - delete this.state.accounts[options?.userId ?? this.state.activeUserId]; + await this.removeAccountFromSessionStorage(options?.userId); + await this.removeAccountFromLocalStorage(options?.userId); + await this.removeAccountFromSecureStorage(options?.userId); + this.removeAccountFromMemory(options?.userId); await this.pushAccounts(); } @@ -1390,4 +1391,38 @@ export class StateService implements StateServiceAbstraction { const state = await this.storageService.get('state', await this.defaultOnDiskOptions()); return state?.activeUserId; } + + private async removeAccountFromLocalStorage(userId: string): Promise { + const state = await this.secureStorageService.get('state', { htmlStorageLocation: HtmlStorageLocation.Local }); + if (state?.accounts[userId ?? this.state.activeUserId] == null) { + return; + } + delete state.accounts[userId ?? this.state.activeUserId] + await this.storageService.save('state', state, { htmlStorageLocation: HtmlStorageLocation.Local }); + } + + private async removeAccountFromSessionStorage(userId: string): Promise { + const state = await this.secureStorageService.get('state', { htmlStorageLocation: HtmlStorageLocation.Session }); + if (state?.accounts[userId ?? this.state.activeUserId] == null) { + return; + } + delete state.accounts[userId ?? this.state.activeUserId] + await this.storageService.save('state', state, { htmlStorageLocation: HtmlStorageLocation.Session }); + } + + private async removeAccountFromSecureStorage(userId: string): Promise { + const state = await this.secureStorageService.get('state'); + if (state?.accounts[userId ?? this.state.activeUserId] == null) { + return; + } + delete state.accounts[userId ?? this.state.activeUserId] + await this.secureStorageService.save('state', state); + } + + private removeAccountFromMemory(userId: string): void { + if (this.state?.accounts[userId ?? this.state.activeUserId] == null) { + return; + } + delete this.state.accounts[userId ?? this.state.activeUserId]; + } }