2025-06-13 23:25:11 +02:00

36 lines
1.1 KiB
JavaScript

const verifyCard = document.getElementById('verify-card');
const successMessage = document.getElementById('success-message');
const verifyButton = document.getElementById('verify-button');
verifyButton.addEventListener('click', async () => {
//token in query string
const token = new URLSearchParams(window.location.search).get('token');
if (!token) {
alert('Verification token is missing. Please check your email for the verification link.');
return;
}
try {
const response = await fetch('/api/verify', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ token: token })
});
if (response.ok) {
successMessage.classList.remove('hidden');
verifyCard.classList.add('hidden');
} else {
const errorData = await response.json();
alert(`Verification failed: ${errorData.message}`);
}
} catch (error) {
console.error('Error during verification:', error);
alert('An error occurred while trying to verify your account.');
}
});