import { CommonModule } from "@angular/common"; import { Component, OnDestroy, OnInit } from "@angular/core"; import { Router } from "@angular/router"; import { BehaviorSubject, Observable } from "rxjs"; import { DesktopFido2UserInterfaceService, DesktopFido2UserInterfaceSession, } from "../../autofill/services/desktop-fido2-user-interface.service"; import { DesktopSettingsService } from "../../platform/services/desktop-settings.service"; // FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush // eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection @Component({ standalone: true, imports: [CommonModule], template: `

Select your passkey


`, }) export class Fido2PlaceholderComponent implements OnInit, OnDestroy { session?: DesktopFido2UserInterfaceSession = null; private cipherIdsSubject = new BehaviorSubject([]); cipherIds$: Observable; constructor( private readonly desktopSettingsService: DesktopSettingsService, private readonly fido2UserInterfaceService: DesktopFido2UserInterfaceService, private readonly router: Router, ) {} ngOnInit() { this.session = this.fido2UserInterfaceService.getCurrentSession(); this.cipherIds$ = this.session?.availableCipherIds$; } async chooseCipher(cipherId: string) { // For now: Set UV to true this.session?.confirmChosenCipher(cipherId, true); await this.router.navigate(["/"]); await this.desktopSettingsService.setModalMode(false); } ngOnDestroy() { this.cipherIdsSubject.complete(); // Clean up the BehaviorSubject } async confirmPasskey() { try { // Retrieve the current UI session to control the flow if (!this.session) { // todo: handle error throw new Error("No session found"); } // If we want to we could submit information to the session in order to create the credential // const cipher = await session.createCredential({ // userHandle: "userHandle2", // userName: "username2", // credentialName: "zxsd2", // rpId: "webauthn.io", // userVerification: true, // }); this.session.notifyConfirmNewCredential(true); // Not sure this clean up should happen here or in session. // The session currently toggles modal on and send us here // But if this route is somehow opened outside of session we want to make sure we clean up? await this.router.navigate(["/"]); await this.desktopSettingsService.setModalMode(false); } catch { // TODO: Handle error appropriately } } async closeModal() { await this.router.navigate(["/"]); await this.desktopSettingsService.setModalMode(false); this.session.notifyConfirmNewCredential(false); // little bit hacky: this.session.confirmChosenCipher(null); } }