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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user