// app/api/signup/route.js
import { NextResponse } from 'next/server';

export async function POST(req) {
  try {
    const body = await req.json();

    const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/auth/signup`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(body),
    });

    const data = await response.json();
    // console.log("Signup response:", data);
    if (!response.ok) {
      return NextResponse.json({ error: data.error || 'Signup failed' }, { status: response.status });
    }

    return NextResponse.json(data, { status: 201 });
  } catch (error) {
    console.error("Signup error:", error);
    console.log("Error details:", error.message);
    return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
  }
}
