import { NextRequest, NextResponse } from 'next/server';

const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://127.0.0.1:3000';

/** Proxy to backend POST /auth/password-reset/confirm. */
export async function POST(req: NextRequest) {
  const body = await req.text();
  try {
    const backendRes = await fetch(`${API}/auth/password-reset/confirm`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body,
    });
    const data = await backendRes.json().catch(() => null);
    return NextResponse.json(data ?? { error: 'Bad response' }, { status: backendRes.status });
  } catch {
    return NextResponse.json({ error: 'Proxy error' }, { status: 502 });
  }
}