From 1d711932ce5431e0d314326034c45d729639774c Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 23 Oct 2025 21:01:19 +0200 Subject: [PATCH] fix: Actually trigger WebAuthn authentication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations :** - Fix misleading 'Authentication completed successfully' message - Ensure WebAuthn is actually triggered, not just pairing process - Provide accurate status messages for WebAuthn operations **Modifications :** - Import secureCredentialsService directly in handleMainPairing - Check for existing credentials and trigger appropriate WebAuthn flow - Separate status messages for credential decryption vs creation - Only show success message after actual WebAuthn completion **Pages affectées :** - src/pages/home/home.ts - Fixed WebAuthn triggering logic --- src/pages/home/home.ts | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/pages/home/home.ts b/src/pages/home/home.ts index 34a1250..71b4f31 100755 --- a/src/pages/home/home.ts +++ b/src/pages/home/home.ts @@ -558,13 +558,41 @@ async function handleMainPairing(): Promise { if (mainStatus) { mainStatus.innerHTML = '
Authenticating with browser...'; } - - // This will trigger the WebAuthn flow and create/decrypt credentials - await prepareAndSendPairingTx(); - - if (mainStatus) { - mainStatus.innerHTML = '✅ Authentication completed successfully'; + + // Import and trigger WebAuthn directly + const { secureCredentialsService } = await import('../../services/secure-credentials.service'); + + // Check if we have existing credentials + const hasCredentials = await secureCredentialsService.hasCredentials(); + + if (hasCredentials) { + console.log('🔓 Existing credentials found, decrypting...'); + if (mainStatus) { + mainStatus.innerHTML = '
Decrypting existing credentials...'; + } + + // This will trigger WebAuthn for decryption + await secureCredentialsService.retrieveCredentials(''); + + if (mainStatus) { + mainStatus.innerHTML = '✅ Credentials decrypted successfully'; + } + } else { + console.log('🔐 No existing credentials, creating new ones...'); + if (mainStatus) { + mainStatus.innerHTML = '
Creating new credentials...'; + } + + // This will trigger WebAuthn for creation + await secureCredentialsService.generateSecureCredentials(''); + + if (mainStatus) { + mainStatus.innerHTML = '✅ New credentials created successfully'; + } } + + // Now proceed with pairing process + await prepareAndSendPairingTx(); // Re-enable button if (mainPairingButton) {