2023-10-25 20:27:32 +02:00
|
|
|
import { Component, Input } from "@angular/core";
|
2024-04-12 09:25:45 +02:00
|
|
|
import { Observable, combineLatest, map, of, switchMap } from "rxjs";
|
2023-10-25 20:27:32 +02:00
|
|
|
|
|
|
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
2024-04-12 09:25:45 +02:00
|
|
|
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
2023-10-25 20:27:32 +02:00
|
|
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
2024-04-12 09:25:45 +02:00
|
|
|
import { UserId } from "@bitwarden/common/types/guid";
|
2023-10-25 20:27:32 +02:00
|
|
|
|
2024-01-17 21:01:24 +01:00
|
|
|
import { enableAccountSwitching } from "../flags";
|
2023-10-25 20:27:32 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-header",
|
|
|
|
templateUrl: "header.component.html",
|
|
|
|
})
|
|
|
|
export class HeaderComponent {
|
|
|
|
@Input() noTheme = false;
|
2024-01-02 16:46:45 +01:00
|
|
|
@Input() hideAccountSwitcher = false;
|
2023-10-25 20:27:32 +02:00
|
|
|
authedAccounts$: Observable<boolean>;
|
2024-04-12 09:25:45 +02:00
|
|
|
constructor(accountService: AccountService, authService: AuthService) {
|
2023-10-25 20:27:32 +02:00
|
|
|
this.authedAccounts$ = accountService.accounts$.pipe(
|
2024-04-12 09:25:45 +02:00
|
|
|
switchMap((accounts) => {
|
2024-01-17 21:01:24 +01:00
|
|
|
if (!enableAccountSwitching()) {
|
2024-04-12 09:25:45 +02:00
|
|
|
return of(false);
|
2023-10-25 20:27:32 +02:00
|
|
|
}
|
|
|
|
|
2024-04-12 09:25:45 +02:00
|
|
|
return combineLatest(
|
|
|
|
Object.keys(accounts).map((id) => authService.authStatusFor$(id as UserId)),
|
|
|
|
).pipe(
|
|
|
|
map((statuses) => statuses.some((status) => status !== AuthenticationStatus.LoggedOut)),
|
|
|
|
);
|
2023-10-25 20:27:32 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|