fix(auth): use SSL-tolerant axios for oauth token/refresh routes
route های token و refresh از fetch بومی Node استفاده میکردند که گواهی self-signed ddev محلی را رد میکرد و خطای 500 میداد. حالا از axiosInstance استفاده میکنند و خطای واقعی backend را با status درست برمیگردانند. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { axiosInstance } from "@/lib/req";
|
||||||
|
|
||||||
export async function POST(request) {
|
export async function POST(request) {
|
||||||
const { refresh_token } = await request.json();
|
const { refresh_token } = await request.json();
|
||||||
@@ -18,14 +19,18 @@ export async function POST(request) {
|
|||||||
formData.append("refresh_token", refresh_token);
|
formData.append("refresh_token", refresh_token);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/oauth/token`, {
|
const res = await axiosInstance.post(
|
||||||
method: "POST",
|
`${API_URL}/oauth/token`,
|
||||||
headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "" },
|
formData.toString(),
|
||||||
body: formData.toString(),
|
{
|
||||||
});
|
headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "" },
|
||||||
const data = await res.json();
|
}
|
||||||
return NextResponse.json(data, { status: res.status });
|
);
|
||||||
} catch {
|
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 });
|
return NextResponse.json({ error: "Refresh request failed" }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { axiosInstance } from "@/lib/req";
|
||||||
|
|
||||||
export async function POST(request) {
|
export async function POST(request) {
|
||||||
const { uuid, code, scope = "nobat724" } = await request.json();
|
const { uuid, code, scope = "nobat724" } = await request.json();
|
||||||
@@ -20,14 +21,18 @@ export async function POST(request) {
|
|||||||
formData.append("scope", scope);
|
formData.append("scope", scope);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/oauth/token`, {
|
const res = await axiosInstance.post(
|
||||||
method: "POST",
|
`${API_URL}/oauth/token`,
|
||||||
headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "" },
|
formData.toString(),
|
||||||
body: formData.toString(),
|
{
|
||||||
});
|
headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "" },
|
||||||
const data = await res.json();
|
}
|
||||||
return NextResponse.json(data, { status: res.status });
|
);
|
||||||
} catch {
|
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 });
|
return NextResponse.json({ error: "Token request failed" }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user