fix: restore automatic WebAuthn authentication without manual button

**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
This commit is contained in:
NicolasCantu 2025-10-23 22:04:08 +02:00
parent 9b3af0b5ea
commit 535bcf5314

View File

@ -546,58 +546,15 @@ async function handleMainPairing(): Promise<void> {
const container = getCorrectDOM('login-4nk-component') as HTMLElement; const container = getCorrectDOM('login-4nk-component') as HTMLElement;
const mainStatus = container.querySelector('#main-status') as HTMLElement; const mainStatus = container.querySelector('#main-status') as HTMLElement;
try {
// Show authentication button that requires user interaction
console.log('🔍 DEBUG: mainStatus element:', mainStatus);
if (mainStatus) {
console.log('🔍 DEBUG: Setting up authentication button...');
mainStatus.innerHTML = `
<div class="auth-container" style="text-align: center; padding: 20px;">
<p style="font-size: 18px; margin-bottom: 20px; color: #333;">🔐 Secure authentication required</p>
<button id="authButton" class="auth-button" style="
background: linear-gradient(135deg, #007bff, #0056b3);
color: white;
border: none;
padding: 16px 32px;
border-radius: 12px;
cursor: pointer;
font-size: 16px;
font-weight: 600;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
margin: 20px 0;
min-width: 250px;
display: block;
margin-left: auto;
margin-right: auto;
">🔐 Authenticate with Browser</button>
<p class="auth-hint" style="color: #6c757d; font-size: 14px; margin-top: 10px; font-style: italic;">Click the button above to authenticate with your browser</p>
</div>
`;
console.log('🔍 DEBUG: Authentication button HTML set');
} else {
console.error('❌ mainStatus element not found!');
throw new Error('Main status element not found');
}
// Wait for user to click the authentication button
await new Promise<void>((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;
}
authButton.addEventListener('click', async () => {
try { try {
// Update UI to show authentication in progress // Update UI to show authentication in progress
if (mainStatus) { if (mainStatus) {
mainStatus.innerHTML = '<div class="spinner"></div><span>Authenticating with browser...</span>'; mainStatus.innerHTML = '<div class="spinner"></div><span>Authenticating with browser...</span>';
} }
// Always trigger WebAuthn flow for authentication
console.log('🔐 Triggering WebAuthn authentication...');
// Import and trigger WebAuthn directly // Import and trigger WebAuthn directly
const { secureCredentialsService } = await import('../../services/secure-credentials.service'); const { secureCredentialsService } = await import('../../services/secure-credentials.service');
@ -632,16 +589,6 @@ async function handleMainPairing(): Promise<void> {
// Now proceed with pairing process // Now proceed with pairing process
await prepareAndSendPairingTx(); await prepareAndSendPairingTx();
resolve();
} catch (error) {
console.error('Authentication failed:', error);
if (mainStatus) {
mainStatus.innerHTML = '<span style="color: var(--error-color)">❌ Authentication failed. Please try again.</span>';
}
reject(error);
}
});
});
} catch (error) { } catch (error) {
console.error('Pairing failed:', error); console.error('Pairing failed:', error);