From 4d94f7a631c7bc90f2c627f25ce15b4e075569f7 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Thu, 3 Mar 2022 13:57:08 -0500 Subject: [PATCH] [bug] Delete stored keys if the value is null (#705) --- common/src/services/state.service.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 33a71902d0..17b1453f3b 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -446,7 +446,7 @@ export class StateService< if (options?.userId == null) { return; } - await this.secureStorageService.save(`${options.userId}${partialKeys.autoKey}`, value, options); + await this.saveSecureStorageKey(partialKeys.autoKey, value, options); } async getCryptoMasterKeyB64(options?: StorageOptions): Promise { @@ -465,11 +465,7 @@ export class StateService< if (options?.userId == null) { return; } - await this.secureStorageService.save( - `${options.userId}${partialKeys.masterKey}`, - value, - options - ); + await this.saveSecureStorageKey(partialKeys.masterKey, value, options); } async getCryptoMasterKeyBiometric(options?: StorageOptions): Promise { @@ -508,11 +504,7 @@ export class StateService< if (options?.userId == null) { return; } - await this.secureStorageService.save( - `${options.userId}${partialKeys.biometricKey}`, - value, - options - ); + await this.saveSecureStorageKey(partialKeys.biometricKey, value, options); } async getDecodedToken(options?: StorageOptions): Promise { @@ -2502,4 +2494,10 @@ export class StateService< : await this.defaultOnDiskOptions(); return this.reconcileOptions(options, defaultOptions); } + + private async saveSecureStorageKey(key: string, value: string, options?: StorageOptions) { + return value == null + ? await this.secureStorageService.remove(`${options.userId}${key}`, options) + : await this.secureStorageService.save(`${options.userId}${key}`, value, options); + } }