Skip to main content

Email Verification

Verify user email addresses to ensure account ownership.


How It Works

  1. User registers with email/password
  2. SyAuth sends a 6-digit verification code to their email
  3. User enters the code in your application
  4. Email is marked as verified

Verification Email

When a user registers, they receive an email containing:

  • A 6-digit verification code
  • Link to your verification page (if configured)
  • Code expires in 1 hour

Implementing Verification

Implementation Examples

'use client';

import { useState } from 'react';

export function VerifyEmailForm({ email }: { email: string }) {
const [code, setCode] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');

const handleVerify = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError('');

try {
const response = await fetch('https://api.syauth.com/e/v1/email/verify/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, code }),
});

if (response.ok) {
alert('Email verified! You can now log in.');
window.location.href = '/login';
} else {
const data = await response.json();
setError(data.error || 'Verification failed');
}
} catch (err) {
setError('Network error');
} finally {
setLoading(false);
}
};

return (
<form onSubmit={handleVerify}>
<p>Enter the 6-digit code sent to {email}</p>
<input
type="text"
value={code}
onChange={(e) => setCode(e.target.value)}
placeholder="000000"
maxLength={6}
pattern="[0-9]{6}"
required
/>
{error && <p className="error">{error}</p>}
<button type="submit" disabled={loading}>
{loading ? 'Verifying...' : 'Verify Email'}
</button>
</form>
);
}

Resend Verification Email

If the user didn't receive the email or code expired:

async function resendVerification(email: string) {
const response = await fetch('https://api.syauth.com/e/v1/email/verify/resend/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email }),
});

if (response.ok) {
alert('Verification email sent');
}
}
<button onClick={() => resendVerification(email)}>
Resend Verification Email
</button>

API Endpoints

Verify Email

POST https://api.syauth.com/e/v1/email/verify/
Content-Type: application/json

{
"email": "[email protected]",
"code": "123456"
}

Success Response:

{
"success": true,
"message": "Email verified successfully"
}

Resend Verification

POST https://api.syauth.com/e/v1/email/verify/resend/
Content-Type: application/json

{
"email": "[email protected]"
}

Response:

{
"success": true,
"message": "Verification email sent"
}

Error Handling

ErrorCauseSolution
invalid_codeWrong verification codeAsk user to check code
code_expiredCode older than 1 hourResend verification
already_verifiedEmail already verifiedProceed to login
user_not_foundEmail not registeredPrompt to register

Checking Verification Status

You can check if a user's email is verified:

const { user } = useSyAuth();

if (!user?.email_verified) {
return <VerifyEmailPrompt email={user?.email} />;
}

Customizing the Email Template

Customize verification emails in the Dashboard:

  1. Go to Email Templates in the sidebar
  2. Select "Registration Confirmation" template
  3. Edit the subject, from name, and body
  4. Use placeholders: {{code}}, {{first_name}}, {{email}}

Next Steps