Email Verification
Verify user email addresses to ensure account ownership.
How It Works
- User registers with email/password
- SyAuth sends a 6-digit verification code to their email
- User enters the code in your application
- 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
- Next.js SDK
- Python / Django
- cURL / API
'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>
);
}
This example performs the verification request using Python requests:
import requests
def verify_email(email, code):
url = "https://api.syauth.com/e/v1/email/verify/"
payload = {
"email": email,
"code": code
}
headers = {
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
return response.json()
curl -X POST https://api.syauth.com/e/v1/email/verify/ \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"code": "123456"
}'
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
| Error | Cause | Solution |
|---|---|---|
invalid_code | Wrong verification code | Ask user to check code |
code_expired | Code older than 1 hour | Resend verification |
already_verified | Email already verified | Proceed to login |
user_not_found | Email not registered | Prompt 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:
- Go to Email Templates in the sidebar
- Select "Registration Confirmation" template
- Edit the subject, from name, and body
- Use placeholders:
{{code}},{{first_name}},{{email}}
Next Steps
- Password Reset - Implement password reset
- Login & Logout - After verification