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 { 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 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user