From ecc212db861151cfa67e045dc47dbb54247b4109 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 15 Jun 2026 00:30:42 +0330 Subject: [PATCH] fix(auth): use SSL-tolerant axios for oauth token/refresh routes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit route های token و refresh از fetch بومی Node استفاده می‌کردند که گواهی self-signed ddev محلی را رد می‌کرد و خطای 500 می‌داد. حالا از axiosInstance استفاده می‌کنند و خطای واقعی backend را با status درست برمی‌گردانند. Co-Authored-By: Claude Opus 4.8 --- app/api/auth/refresh/route.js | 21 +++++++++++++-------- app/api/auth/token/route.js | 21 +++++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/api/auth/refresh/route.js b/app/api/auth/refresh/route.js index dca4e65..0246478 100644 --- a/app/api/auth/refresh/route.js +++ b/app/api/auth/refresh/route.js @@ -1,4 +1,5 @@ import { NextResponse } from "next/server"; +import { axiosInstance } from "@/lib/req"; export async function POST(request) { const { refresh_token } = await request.json(); @@ -18,14 +19,18 @@ export async function POST(request) { formData.append("refresh_token", refresh_token); try { - const res = await fetch(`${API_URL}/oauth/token`, { - method: "POST", - headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "" }, - body: formData.toString(), - }); - const data = await res.json(); - return NextResponse.json(data, { status: res.status }); - } catch { + const res = await axiosInstance.post( + `${API_URL}/oauth/token`, + formData.toString(), + { + headers: { "Content-Type": "application/x-www-form-urlencoded", 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 }); } } diff --git a/app/api/auth/token/route.js b/app/api/auth/token/route.js index cf2cf3b..4920da6 100644 --- a/app/api/auth/token/route.js +++ b/app/api/auth/token/route.js @@ -1,4 +1,5 @@ import { NextResponse } from "next/server"; +import { axiosInstance } from "@/lib/req"; export async function POST(request) { const { uuid, code, scope = "nobat724" } = await request.json(); @@ -20,14 +21,18 @@ export async function POST(request) { formData.append("scope", scope); try { - const res = await fetch(`${API_URL}/oauth/token`, { - method: "POST", - headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "" }, - body: formData.toString(), - }); - const data = await res.json(); - return NextResponse.json(data, { status: res.status }); - } catch { + const res = await axiosInstance.post( + `${API_URL}/oauth/token`, + formData.toString(), + { + headers: { "Content-Type": "application/x-www-form-urlencoded", 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: "Token request failed" }, { status: 500 }); } }