diff --git a/app/api/captcha/route.js b/app/api/captcha/route.js index 230c5ac..60e45a9 100644 --- a/app/api/captcha/route.js +++ b/app/api/captcha/route.js @@ -1,26 +1,20 @@ -import svgCaptcha from 'svg-captcha'; +import captcha from 'trek-captcha'; import { NextResponse } from 'next/server'; import crypto from 'crypto'; -// Prevent Next.js from evaluating this route at build time export const dynamic = 'force-dynamic'; export async function GET() { - const captcha = svgCaptcha.create({ - size: 5, - ignoreChars: '0o1i', - noise: 2, - color: true, - background: '#f3f4f6' - }); + // Generate a 4-character alphanumeric captcha + const { token, buffer } = await captcha({ size: 4, style: -1 }); - const text = captcha.text.toLowerCase(); + const text = token.toLowerCase(); const secret = process.env.CAPTCHA_SECRET || 'dev_secret_meow'; const hash = crypto.createHmac('sha256', secret).update(text).digest('hex'); - const response = new NextResponse(captcha.data, { + const response = new NextResponse(buffer, { headers: { - 'Content-Type': 'image/svg+xml', + 'Content-Type': 'image/gif', 'Cache-Control': 'no-store, max-age=0' } });