1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-12-05 09:14:28 +01:00

cli status command shows locked status when unlocked

This commit is contained in:
Maciej Zieniuk 2025-11-27 21:08:06 +00:00
parent d7dcdf2f03
commit acc8a903a5
No known key found for this signature in database
GPG Key ID: 9CACE59F1272ACD9
3 changed files with 14 additions and 5 deletions

View File

@ -1,12 +1,12 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { firstValueFrom, map } from "rxjs";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { UserAutoUnlockKeyService } from "@bitwarden/common/platform/services/user-auto-unlock-key.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { UserId } from "@bitwarden/user-core";
import { Response } from "../models/response";
import { TemplateResponse } from "../models/response/template.response";
@ -17,16 +17,17 @@ export class StatusCommand {
private syncService: SyncService,
private accountService: AccountService,
private authService: AuthService,
private userAutoUnlockKeyService: UserAutoUnlockKeyService,
) {}
async run(): Promise<Response> {
try {
const baseUrl = await this.baseUrl();
const status = await this.status();
const lastSync = await this.syncService.getLastSync();
const [userId, email] = await firstValueFrom(
this.accountService.activeAccount$.pipe(map((a) => [a?.id, a?.email])),
);
const status = await this.status(userId);
return Response.success(
new TemplateResponse({
@ -42,12 +43,18 @@ export class StatusCommand {
}
}
private async baseUrl(): Promise<string> {
private async baseUrl(): Promise<string | undefined> {
const env = await firstValueFrom(this.envService.environment$);
return env.getUrls().base;
}
private async status(): Promise<"unauthenticated" | "locked" | "unlocked"> {
private async status(
userId: UserId | undefined,
): Promise<"unauthenticated" | "locked" | "unlocked"> {
if (userId != null) {
await this.userAutoUnlockKeyService.setUserKeyInMemoryIfAutoUserKeySet(userId);
}
const authStatus = await this.authService.getAuthStatus();
if (authStatus === AuthenticationStatus.Unlocked) {
return "unlocked";

View File

@ -122,6 +122,7 @@ export class OssServeConfigurator {
this.serviceContainer.syncService,
this.serviceContainer.accountService,
this.serviceContainer.authService,
this.serviceContainer.userAutoUnlockKeyService,
);
this.deleteCommand = new DeleteCommand(
this.serviceContainer.cipherService,

View File

@ -517,6 +517,7 @@ export class Program extends BaseProgram {
this.serviceContainer.syncService,
this.serviceContainer.accountService,
this.serviceContainer.authService,
this.serviceContainer.userAutoUnlockKeyService,
);
const response = await command.run();
this.processResponse(response);