[bug] Delete stored keys if the value is null (#705)

This commit is contained in:
Addison Beck 2022-03-03 13:57:08 -05:00 committed by GitHub
parent 813457c348
commit 4d94f7a631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 11 deletions

View File

@ -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<string> {
@ -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<string> {
@ -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<any> {
@ -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);
}
}