curl --request POST \
--url https://api.example.com/api/auth/verify \
--header 'Content-Type: application/json' \
--data '
{
"verificationToken": "<string>"
}
'{
"verified": true,
"user": {
"email": "<string>",
"username": "<string>"
}
}Verify a user’s email address using a verification token
curl --request POST \
--url https://api.example.com/api/auth/verify \
--header 'Content-Type: application/json' \
--data '
{
"verificationToken": "<string>"
}
'{
"verified": true,
"user": {
"email": "<string>",
"username": "<string>"
}
}emailVerified field is set to true and the verification token is removed from their account.
true in success responses).curl -X POST https://your-domain.com/api/auth/verify \
-H "Content-Type: application/json" \
-d '{
"verificationToken": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"
}'
{
"verified": true,
"user": {
"email": "[email protected]",
"username": "Alice Johnson"
}
}
{
"error": "Invalid verification token"
}
{
"error": "No User found."
}
{
"error": "Error Verifying email."
}
null and cannot be reused.verificationToken not provided in request body or is emptynull after verification)verificationTokenemailVerified to trueverificationToken to null{
emailVerified: true, // Changed from false
verificationToken: null // Cleared to prevent reuse
}
// Step 1: Sign up
const signupResponse = await fetch('/api/auth/signup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: '[email protected]',
name: 'Alice Johnson',
password: 'SecurePass123!',
}),
});
const { verificationToken } = await signupResponse.json();
// Step 2: Send verification email (implement your email service)
await sendVerificationEmail('[email protected]', verificationToken);
// Step 3: User clicks verification link, extract token from URL
const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token');
// Step 4: Verify email
const verifyResponse = await fetch('/api/auth/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ verificationToken: token }),
});
const result = await verifyResponse.json();
if (result.verified) {
// Step 5: Redirect to sign in
window.location.href = '/signin';
}
isEmailVerified flag in their session will be true