diff --git a/apps/cli/src/bw.ts b/apps/cli/src/bw.ts index 753bfe3666..d7ce250a71 100644 --- a/apps/cli/src/bw.ts +++ b/apps/cli/src/bw.ts @@ -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() { diff --git a/apps/cli/src/program.ts b/apps/cli/src/program.ts index 5d26b0850e..9664b75776 100644 --- a/apps/cli/src/program.ts +++ b/apps/cli/src/program.ts @@ -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:*", () => {