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:
parent
9b3af0b5ea
commit
535bcf5314
@ -547,101 +547,48 @@ async function handleMainPairing(): Promise<void> {
|
|||||||
const mainStatus = container.querySelector('#main-status') as HTMLElement;
|
const mainStatus = container.querySelector('#main-status') as HTMLElement;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Show authentication button that requires user interaction
|
// Update UI to show authentication in progress
|
||||||
console.log('🔍 DEBUG: mainStatus element:', mainStatus);
|
|
||||||
if (mainStatus) {
|
if (mainStatus) {
|
||||||
console.log('🔍 DEBUG: Setting up authentication button...');
|
mainStatus.innerHTML = '<div class="spinner"></div><span>Authenticating with browser...</span>';
|
||||||
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
|
// Always trigger WebAuthn flow for authentication
|
||||||
await new Promise<void>((resolve, reject) => {
|
console.log('🔐 Triggering WebAuthn authentication...');
|
||||||
console.log('🔍 DEBUG: Looking for authButton...');
|
|
||||||
const authButton = document.getElementById('authButton') as HTMLButtonElement;
|
// Import and trigger WebAuthn directly
|
||||||
console.log('🔍 DEBUG: authButton found:', authButton);
|
const { secureCredentialsService } = await import('../../services/secure-credentials.service');
|
||||||
if (!authButton) {
|
|
||||||
console.error('❌ Authentication button not found in DOM');
|
// Check if we have existing credentials
|
||||||
reject(new Error('Authentication button not found'));
|
const hasCredentials = await secureCredentialsService.hasCredentials();
|
||||||
return;
|
|
||||||
|
if (hasCredentials) {
|
||||||
|
console.log('🔓 Existing credentials found, decrypting...');
|
||||||
|
if (mainStatus) {
|
||||||
|
mainStatus.innerHTML = '<div class="spinner"></div><span>Decrypting existing credentials...</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
authButton.addEventListener('click', async () => {
|
// This will trigger WebAuthn for decryption
|
||||||
try {
|
await secureCredentialsService.retrieveCredentials('');
|
||||||
// Update UI to show authentication in progress
|
|
||||||
if (mainStatus) {
|
|
||||||
mainStatus.innerHTML = '<div class="spinner"></div><span>Authenticating with browser...</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Import and trigger WebAuthn directly
|
if (mainStatus) {
|
||||||
const { secureCredentialsService } = await import('../../services/secure-credentials.service');
|
mainStatus.innerHTML = '<span style="color: var(--success-color)">✅ Credentials decrypted successfully</span>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('🔐 No existing credentials, creating new ones...');
|
||||||
|
if (mainStatus) {
|
||||||
|
mainStatus.innerHTML = '<div class="spinner"></div><span>Creating new credentials...</span>';
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we have existing credentials
|
// This will trigger WebAuthn for creation
|
||||||
const hasCredentials = await secureCredentialsService.hasCredentials();
|
await secureCredentialsService.generateSecureCredentials('');
|
||||||
|
|
||||||
if (hasCredentials) {
|
if (mainStatus) {
|
||||||
console.log('🔓 Existing credentials found, decrypting...');
|
mainStatus.innerHTML = '<span style="color: var(--success-color)">✅ New credentials created successfully</span>';
|
||||||
if (mainStatus) {
|
}
|
||||||
mainStatus.innerHTML = '<div class="spinner"></div><span>Decrypting existing credentials...</span>';
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// This will trigger WebAuthn for decryption
|
// Now proceed with pairing process
|
||||||
await secureCredentialsService.retrieveCredentials('');
|
await prepareAndSendPairingTx();
|
||||||
|
|
||||||
if (mainStatus) {
|
|
||||||
mainStatus.innerHTML = '<span style="color: var(--success-color)">✅ Credentials decrypted successfully</span>';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('🔐 No existing credentials, creating new ones...');
|
|
||||||
if (mainStatus) {
|
|
||||||
mainStatus.innerHTML = '<div class="spinner"></div><span>Creating new credentials...</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// This will trigger WebAuthn for creation
|
|
||||||
await secureCredentialsService.generateSecureCredentials('');
|
|
||||||
|
|
||||||
if (mainStatus) {
|
|
||||||
mainStatus.innerHTML = '<span style="color: var(--success-color)">✅ New credentials created successfully</span>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now proceed with pairing process
|
|
||||||
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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user