From 172a3b40b1864382e2c65fdffb46f1a071bc212d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=85berg?= Date: Fri, 24 Jan 2025 12:24:04 +0100 Subject: [PATCH] Clean up --- .husky/pre-commit | 1 + .../components/fido2placeholder.component.ts | 16 ++++++------- .../desktop-fido2-user-interface.service.ts | 23 ++++++------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index e69de29bb2d..d0a778429a3 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npx lint-staged \ No newline at end of file diff --git a/apps/desktop/src/app/components/fido2placeholder.component.ts b/apps/desktop/src/app/components/fido2placeholder.component.ts index 00c3499be43..1669d82e077 100644 --- a/apps/desktop/src/app/components/fido2placeholder.component.ts +++ b/apps/desktop/src/app/components/fido2placeholder.component.ts @@ -44,19 +44,16 @@ export class Fido2PlaceholderComponent { async confirmPasskey() { const desktopUiService = this.fido2UserInterfaceService as DesktopFido2UserInterfaceService; - console.log("Got desktopService", desktopUiService.guid); try { - console.log("checking for session", this.fido2UserInterfaceService); - // Add timeout to avoid infinite hanging + // Retrieve the current UI session to control the flow const session = desktopUiService.getCurrentSession(); if (!session) { // todo: handle error - console.error("No session found"); - return; + throw new Error("No session found"); } - console.log("Got session", session.guid); + // 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", @@ -66,11 +63,14 @@ export class Fido2PlaceholderComponent { // }); session.notifyOperationCompleted(); + + // 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.setInModalMode(false); } catch (error) { - console.error("Failed during confirmation:", error); - // Handle error appropriately + // TODO: Handle error appropriately } } diff --git a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts index 55026c18fec..d9c8b573664 100644 --- a/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts +++ b/apps/desktop/src/autofill/services/desktop-fido2-user-interface.service.ts @@ -1,5 +1,5 @@ import { Router } from "@angular/router"; -import { filter, lastValueFrom, firstValueFrom, map, shareReplay, Subject, tap } from "rxjs"; +import { lastValueFrom, firstValueFrom, map, Subject } from "rxjs"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; @@ -21,7 +21,7 @@ import { IdentityView } from "@bitwarden/common/vault/models/view/identity.view" import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view"; import { LoginView } from "@bitwarden/common/vault/models/view/login.view"; import { SecureNoteView } from "@bitwarden/common/vault/models/view/secure-note.view"; -import { UsernameAlgorithms } from "@bitwarden/generator-core"; + import { DesktopSettingsService } from "src/platform/services/desktop-settings.service"; // import the angular router @@ -37,10 +37,7 @@ export class DesktopFido2UserInterfaceService private messagingService: MessagingService, private router: Router, private desktopSettingsService: DesktopSettingsService, - ) { - this.guid = "PARENT" + Math.random().toString(36).substring(7); - } - guid: string; + ) {} private currentSession: any; getCurrentSession(): DesktopFido2UserInterfaceSession | undefined { @@ -63,9 +60,6 @@ export class DesktopFido2UserInterfaceService this.desktopSettingsService, ); - console.log("In parent", this.guid); - console.log("Setting current session", session.guid); - this.currentSession = session; return session; } @@ -80,11 +74,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi private messagingService: MessagingService, private router: Router, private desktopSettingsService: DesktopSettingsService, - ) { - this.guid = "SESSION" + Math.random().toString(36).substring(7); - } - - guid: string; + ) {} pickCredential: ( params: PickCredentialParams, @@ -130,7 +120,7 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi try { // Load the UI: - // maybe this modal mode thing shouldn't be done here? + // maybe toggling to modal mode shouldn't be done here? await this.desktopSettingsService.setInModalMode(true); await this.router.navigate(["/passkeys"]); @@ -143,16 +133,17 @@ export class DesktopFido2UserInterfaceSession implements Fido2UserInterfaceSessi userHandle: "", userVerification, }); - console.log("Returning from confirmNewCredential, created cipher:", this.createdCipher); // wait for 10ms to help RXJS catch up(?) // We sometimes get a race condition from this.createCredential not updating cipherService in time //console.log("waiting 10ms.."); //await new Promise((resolve) => setTimeout(resolve, 10)); //console.log("Just waited 10ms"); + // Return the new cipher (this.createdCipher) return { cipherId: this.createdCipher.id, userVerified: userVerification }; } finally { + // Make sure to clean up so the app is never stuck in modal mode? await this.desktopSettingsService.setInModalMode(false); } }