import { NextResponse } from "next/server"; import { axiosInstance } from "@/lib/req"; export async function POST(request) { const { uuid, code } = await request.json(); const API_URL = process.env.NEXT_PUBLIC_API_URL; if (!uuid || !code) { return NextResponse.json({ error: "uuid and code are required" }, { status: 400 }); } const jsonHeaders = { "Content-Type": "application/json", Authorization: "" }; try { // مرحله ۱: تأیید OTP — بدون این، oauth/token کد را verified نمی‌بیند await axiosInstance.post( `${API_URL}/api/v1/user/verify-code`, { uuid, code }, { headers: jsonHeaders } ); // مرحله ۲: تبدیل uuid تأییدشده به توکن const res = await axiosInstance.post( `${API_URL}/oauth/token`, { grant_type: "mobile", uuid }, { headers: jsonHeaders } ); return NextResponse.json(res.data, { status: res.status }); } catch (error) { if (error.response) { return NextResponse.json(error.response.data, { status: error.response.status }); } return NextResponse.json({ error: "Token request failed" }, { status: 500 }); } }