backend جدید clinicpro جریان سهمرحلهای دارد:
send-code → verify-code (uuid+code) → oauth/token (uuid).
- token route حالا اول /api/v1/user/verify-code را صدا میزند سپس
/oauth/token با بدنه JSON {grant_type, uuid} (بهجای form-urlencoded
با client_id/secret/scope که فقط backend پروداکشن قدیم میپذیرفت)
- refresh route به مسیر درست /oauth/token/refresh با بدنه JSON
- تست E2E روی ddev محلی: access_token واقعی صادر شد
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
853 B
JavaScript
29 lines
853 B
JavaScript
import { NextResponse } from "next/server";
|
|
import { axiosInstance } from "@/lib/req";
|
|
|
|
export async function POST(request) {
|
|
const { refresh_token } = await request.json();
|
|
|
|
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
|
|
|
if (!refresh_token) {
|
|
return NextResponse.json({ error: "refresh_token is required" }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const res = await axiosInstance.post(
|
|
`${API_URL}/oauth/token/refresh`,
|
|
{ refresh_token },
|
|
{
|
|
headers: { "Content-Type": "application/json", Authorization: "" },
|
|
}
|
|
);
|
|
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: "Refresh request failed" }, { status: 500 });
|
|
}
|
|
}
|