mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
Auth/PM-10684 - Fix CLI asking for MP even if session key provided as command option (#10917)
* PM-10684 - ServiceContainer - Add better docs * PM-10684 - UserAutoUnlockKeyService - setUserKeyInMemoryIfAutoUserKeySet - refactor method to return a bool instead of nothing so users can know if a user key was retrieved & set without another call. * PM-10684 - Remove async code ( Program.ts) responsible for setting the auto user key from the session option handler (event emitter which fires when a user passes --session <sessionKey> to a command). Returning this to synchronous execution prevents a race condition between the setting of the user key and the command executing the exitIfLocked logic in the base-program which would check if the user key had been set to determine if the command should be allowed to execute or if the user was locked. When running a loop from a script, the command would often trigger the exitIfLocked before the auto user key could be set in state from the option:session session. * PM-10684 - Clean up missed item per PR feedback
This commit is contained in:
@@ -16,10 +16,11 @@ export class UserAutoUnlockKeyService {
|
||||
* However, for users that have the auto unlock user key set, we need to set the user key in memory
|
||||
* on application bootstrap and on active account changes so that the user's vault loads unlocked.
|
||||
* @param userId - The user id to check for an auto user key.
|
||||
* @returns True if the auto user key is set successfully, false otherwise.
|
||||
*/
|
||||
async setUserKeyInMemoryIfAutoUserKeySet(userId: UserId): Promise<void> {
|
||||
async setUserKeyInMemoryIfAutoUserKeySet(userId: UserId): Promise<boolean> {
|
||||
if (userId == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const autoUserKey = await this.cryptoService.getUserKeyFromStorage(
|
||||
@@ -28,9 +29,10 @@ export class UserAutoUnlockKeyService {
|
||||
);
|
||||
|
||||
if (autoUserKey == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
await this.cryptoService.setUserKey(autoUserKey, userId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user