Files
biblical-guide.com/app/api/captcha/route.ts
Andrei 989f231d5a feat: add captcha verification to contact form
Added math-based captcha system to prevent spam on the contact form:
- Created captcha API endpoint with simple arithmetic questions
- Added captcha UI component with refresh functionality
- Integrated captcha verification into contact form submission
- Relaxed spam filters since captcha provides better protection

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-10 17:53:56 +00:00

51 lines
1.2 KiB
TypeScript

import { NextResponse } from 'next/server'
import { generateCaptcha, verifyCaptcha } from '@/lib/captcha'
export const runtime = 'nodejs'
export async function GET() {
try {
const captchaData = generateCaptcha()
return NextResponse.json({
success: true,
captchaId: captchaData.captchaId,
question: captchaData.question
})
} catch (error) {
console.error('Captcha generation error:', error)
return NextResponse.json({
success: false,
error: 'Failed to generate captcha'
}, { status: 500 })
}
}
export async function POST(request: Request) {
try {
const { captchaId, answer } = await request.json()
if (!captchaId || answer === undefined) {
return NextResponse.json({
success: false,
error: 'Missing captcha ID or answer'
}, { status: 400 })
}
const isValid = verifyCaptcha(captchaId, answer)
return NextResponse.json({
success: true,
valid: isValid
})
} catch (error) {
console.error('Captcha verification error:', error)
return NextResponse.json({
success: false,
error: 'Failed to verify captcha'
}, { status: 500 })
}
}