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); + } }