From 535bcf5314fb97fe62ba9095a76723a195fb220a Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 23 Oct 2025 22:04:08 +0200 Subject: [PATCH] fix: restore automatic WebAuthn authentication without manual button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Motivations :** - Remove manual authentication button as requested by user - Restore automatic WebAuthn triggering like before - Maintain seamless user experience without manual intervention - Keep WebAuthn security while ensuring automatic flow **Modifications :** - Removed manual authentication button and click handler - Restored automatic WebAuthn triggering in handleMainPairing() - Simplified authentication flow to be automatic on page load - Maintained proper error handling and user feedback - Kept spinner and status messages for user feedback **Pages affectΓ©es :** - src/pages/home/home.ts: Restored automatic WebAuthn authentication flow --- src/pages/home/home.ts | 119 ++++++++++++----------------------------- 1 file changed, 33 insertions(+), 86 deletions(-) diff --git a/src/pages/home/home.ts b/src/pages/home/home.ts index 151e500..d7ebf43 100755 --- a/src/pages/home/home.ts +++ b/src/pages/home/home.ts @@ -547,101 +547,48 @@ async function handleMainPairing(): Promise { const mainStatus = container.querySelector('#main-status') as HTMLElement; try { - // Show authentication button that requires user interaction - console.log('πŸ” DEBUG: mainStatus element:', mainStatus); + // Update UI to show authentication in progress if (mainStatus) { - console.log('πŸ” DEBUG: Setting up authentication button...'); - mainStatus.innerHTML = ` -
-

πŸ” Secure authentication required

- -

Click the button above to authenticate with your browser

-
- `; - console.log('πŸ” DEBUG: Authentication button HTML set'); - } else { - console.error('❌ mainStatus element not found!'); - throw new Error('Main status element not found'); + mainStatus.innerHTML = '
Authenticating with browser...'; } - // Wait for user to click the authentication button - await new Promise((resolve, reject) => { - console.log('πŸ” DEBUG: Looking for authButton...'); - const authButton = document.getElementById('authButton') as HTMLButtonElement; - console.log('πŸ” DEBUG: authButton found:', authButton); - if (!authButton) { - console.error('❌ Authentication button not found in DOM'); - reject(new Error('Authentication button not found')); - return; + // Always trigger WebAuthn flow for authentication + console.log('πŸ” Triggering WebAuthn authentication...'); + + // 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...'; } - authButton.addEventListener('click', async () => { - try { - // Update UI to show authentication in progress - if (mainStatus) { - mainStatus.innerHTML = '
Authenticating with browser...'; - } + // This will trigger WebAuthn for decryption + await secureCredentialsService.retrieveCredentials(''); - // Import and trigger WebAuthn directly - const { secureCredentialsService } = await import('../../services/secure-credentials.service'); + if (mainStatus) { + mainStatus.innerHTML = 'βœ… Credentials decrypted successfully'; + } + } else { + console.log('πŸ” No existing credentials, creating new ones...'); + if (mainStatus) { + mainStatus.innerHTML = '
Creating new credentials...'; + } - // Check if we have existing credentials - const hasCredentials = await secureCredentialsService.hasCredentials(); + // This will trigger WebAuthn for creation + await secureCredentialsService.generateSecureCredentials(''); - if (hasCredentials) { - console.log('πŸ”“ Existing credentials found, decrypting...'); - if (mainStatus) { - mainStatus.innerHTML = '
Decrypting existing credentials...'; - } + if (mainStatus) { + mainStatus.innerHTML = 'βœ… New credentials created successfully'; + } + } - // 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(); - resolve(); - } catch (error) { - console.error('Authentication failed:', error); - if (mainStatus) { - mainStatus.innerHTML = '❌ Authentication failed. Please try again.'; - } - reject(error); - } - }); - }); + // Now proceed with pairing process + await prepareAndSendPairingTx(); } catch (error) { console.error('Pairing failed:', error);