1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-23 16:13:21 +00:00
Files
browser/apps/web/src/app/layouts/header/account-menu.component.ts
William Martin 73f31fd828 refactor: update web header to use bit-header component
- Refactor web-header to use new bit-header component from libs/components
  - Extract account menu to separate component
  - Update header module to import HeaderComponent
2025-11-25 12:42:12 -05:00

51 lines
1.9 KiB
TypeScript

import { ChangeDetectionStrategy, Component, inject } from "@angular/core";
import { toSignal } from "@angular/core/rxjs-interop";
import { map, Observable } from "rxjs";
import { LockService, LogoutService } from "@bitwarden/auth/common";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import {
VaultTimeoutAction,
VaultTimeoutSettingsService,
} from "@bitwarden/common/key-management/vault-timeout";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DynamicAvatarComponent } from "../../components/dynamic-avatar.component";
import { SharedModule } from "../../shared";
@Component({
selector: "app-account-menu",
templateUrl: "./account-menu.component.html",
imports: [SharedModule, DynamicAvatarComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AccountMenuComponent {
private readonly platformUtilsService = inject(PlatformUtilsService);
private readonly vaultTimeoutSettingsService = inject(VaultTimeoutSettingsService);
private readonly accountService = inject(AccountService);
private readonly logoutService = inject(LogoutService);
private readonly lockService = inject(LockService);
protected readonly account = toSignal(this.accountService.activeAccount$);
protected readonly canLock$: Observable<boolean> = this.vaultTimeoutSettingsService
.availableVaultTimeoutActions$()
.pipe(map((actions) => actions.includes(VaultTimeoutAction.Lock)));
protected readonly selfHosted = this.platformUtilsService.isSelfHost();
protected readonly hostname = globalThis.location.hostname;
protected async lock() {
const userId = this.account()?.id;
if (userId) {
await this.lockService.lock(userId);
}
}
protected async logout() {
const userId = this.account()?.id;
if (userId) {
await this.logoutService.logout(userId);
}
}
}