set user key once we detect session key (#9084)

This commit is contained in:
Jake Fink 2024-05-08 14:48:49 -04:00 committed by GitHub
parent a42de41587
commit b4257e1c1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -701,6 +701,8 @@ export class Main {
this.organizationExportService,
);
this.userAutoUnlockKeyService = new UserAutoUnlockKeyService(this.cryptoService);
this.auditService = new AuditService(this.cryptoFunctionService, this.apiService);
this.program = new Program(this);
this.vaultProgram = new VaultProgram(this);
@ -724,8 +726,6 @@ export class Main {
);
this.providerApiService = new ProviderApiService(this.apiService);
this.userAutoUnlockKeyService = new UserAutoUnlockKeyService(this.cryptoService);
}
async run() {

View File

@ -1,5 +1,6 @@
import * as chalk from "chalk";
import { program, Command, OptionValues } from "commander";
import { firstValueFrom } from "rxjs";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
@ -63,8 +64,16 @@ export class Program {
process.env.BW_NOINTERACTION = "true";
});
program.on("option:session", (key) => {
program.on("option:session", async (key) => {
process.env.BW_SESSION = key;
// once we have the session key, we can set the user key in memory
const activeAccount = await firstValueFrom(this.main.accountService.activeAccount$);
if (activeAccount) {
await this.main.userAutoUnlockKeyService.setUserKeyInMemoryIfAutoUserKeySet(
activeAccount.id,
);
}
});
program.on("command:*", () => {