// app/api/brein/route.ts
import { NextResponse } from 'next/server'
const BREIN_RESPONSES_URL = 'https://api.trybrein.com/api/v1/forms/frm_AbC123dEf4/responses'
export async function POST(request: Request) {
const data = await request.formData()
const response = await fetch(BREIN_RESPONSES_URL, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.BREIN_FORM_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
answers: {
nombre: String(data.get('nombre') ?? ''),
correo: String(data.get('correo') ?? ''),
},
consent: { privacy: data.get('privacy') === 'on' },
}),
})
if (!response.ok) {
return NextResponse.json(await response.json(), { status: response.status })
}
return NextResponse.redirect(new URL('/gracias', request.url), 303)
}