import { NextResponse } from 'next/server'; import { cookies } from 'next/headers'; import { verifyToken } from '@/lib/auth'; export async function POST(request: Request) { try { const cookieStore = await cookies(); const token = cookieStore.get('hub_token')?.value; if (!token) return NextResponse.json({ error: 'No autorizado' }, { status: 401 }); const user = await verifyToken(token) as any; if (!user) return NextResponse.json({ error: 'Token inválido' }, { status: 401 }); const body = await request.json(); const { title, description, urgency } = body; const apiKey = process.env.PLANE_API_KEY; const apiUrl = process.env.PLANE_API_URL; const workspace = process.env.PLANE_WORKSPACE_SLUG; const projectId = process.env.PLANE_PROJECT_ID; if (!apiKey || !apiUrl || !workspace || !projectId) { return NextResponse.json({ error: 'Faltan variables de entorno para la conexión con Plane' }, { status: 500 }); } const companyPrefix = user.companyName ? `[${user.companyName.toUpperCase()}] ` : ''; const planeData = { name: `${companyPrefix}${title}`, description_html: `
Reportado por: ${user.email}
${description.replace(/\n/g, '
')}