// Email Verification Handler document.addEventListener('DOMContentLoaded', async () => { const statusDiv = document.getElementById('verification-status'); // Get token from URL query parameters const urlParams = new URLSearchParams(window.location.search); const token = urlParams.get('token'); if (!token) { showError('Invalid verification link - no token provided'); return; } try { // Call API to verify token const response = await fetch(`/api/verify-email/${token}`, { method: 'GET', headers: { 'Content-Type': 'application/json' }, credentials: 'include' // Important for session management }); const data = await response.json(); if (data.success) { // Store campaign data in session storage for dashboard if (data.campaignData) { sessionStorage.setItem('pendingCampaign', JSON.stringify(data.campaignData)); } // Show success and redirect if (data.isNewUser) { showSuccess( '✅ Welcome! Your account has been created successfully. Check your email for login credentials. Your email content is ready - just add a campaign title and description!', '/dashboard.html', 'Go to Dashboard', 4000 ); } else if (data.needsAccount) { showSuccess( 'Email verified! Please create your account to continue.', '/login.html', 'Go to Login', 3000 ); } else { showSuccess( 'Email verified! Redirecting to campaign creation...', '/dashboard.html', 'Go to Dashboard', 2000 ); } } else { showError(data.error || 'Verification failed'); } } catch (error) { console.error('Verification error:', error); showError('An error occurred during verification. Please try again or contact support.'); } }); function showSuccess(message, redirectUrl, buttonText, autoRedirectDelay = 3000) { const statusDiv = document.getElementById('verification-status'); statusDiv.innerHTML = `