1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

Fix and test hasUserKey implementation (#8336)

This commit is contained in:
Matt Gibson
2024-03-14 19:59:30 -05:00
committed by GitHub
parent 5506842623
commit e9a34ac5b8
4 changed files with 67 additions and 8 deletions

View File

@@ -202,13 +202,23 @@ export class CryptoService implements CryptoServiceAbstraction {
}
}
async hasUserKey(): Promise<boolean> {
async hasUserKey(userId?: UserId): Promise<boolean> {
userId ??= await firstValueFrom(this.stateProvider.activeUserId$);
if (userId == null) {
return false;
}
return (
(await this.hasUserKeyInMemory()) || (await this.hasUserKeyStored(KeySuffixOptions.Auto))
(await this.hasUserKeyInMemory(userId)) ||
(await this.hasUserKeyStored(KeySuffixOptions.Auto, userId))
);
}
async hasUserKeyInMemory(userId?: UserId): Promise<boolean> {
userId ??= await firstValueFrom(this.stateProvider.activeUserId$);
if (userId == null) {
return false;
}
return (await firstValueFrom(this.stateProvider.getUserState$(USER_KEY, userId))) != null;
}