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 }); } }