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);