// app/api/users/[id]/route.ts import { NextResponse } from "next/server"; const BE_BASE_URL = process.env.BE_BASE_URL || "http://localhost:5000"; const COOKIE_NAME = "auth_token"; export async function PATCH( request: Request, { params }: { params: { id: string } } ) { try { console.log("[PATCH /users] - params", params); const { id } = params; const body = await request.json(); // Get the auth token from cookies const { cookies } = await import("next/headers"); const cookieStore = cookies(); const token = (await cookieStore).get(COOKIE_NAME)?.value; if (!token) { return NextResponse.json( { message: "Missing Authorization header" }, { status: 401 } ); } const response = await fetch(`${BE_BASE_URL}/users/${id}`, { method: "PATCH", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, body: JSON.stringify(body), }); const data = await response.json(); return NextResponse.json(data, { status: response.status }); } catch (err: any) { console.error("Proxy PATCH /users error:", err); return NextResponse.json( { message: "Internal server error", error: err.message }, { status: 500 } ); } }