fix(api): fix token handler

This commit is contained in:
2026-03-09 13:57:47 +08:00
parent 3b118e3304
commit e7670c7cef
4 changed files with 55 additions and 41 deletions

View File

@@ -46,32 +46,45 @@ export async function POST(req: any) {
}
)
}
const userData = await genAccessToken(req)
const authorization = `bearer ${userData?.access_token}`
let fetchOptions: any = {}
const fetchOptions: any = {
method,
headers: {
"content-type": "application/json",
authorization: authorization,
},
}
if (method === "POST" || method === "PUT") {
let refreshBody = JSON.stringify({
...JSON.parse(data),
token: userData?.refresh_token || "",
})
fetchOptions.body = isRefresh ? refreshBody : data
if (isRefresh) {
if (!userData?.refresh_token) {
return NextResponse.json(
{ message: "Refresh token is empty", code: 406 },
{ status: 200 }
)
}
fetchOptions = {
method,
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
token: userData?.refresh_token,
}),
}
} else {
if (isParamsValid(data)) {
let test = ""
for (const [key, value] of Object.entries(data)) {
test += `&${key}=${value}`
const authorization = `bearer ${userData?.access_token}`
fetchOptions = {
method,
headers: {
"content-type": "application/json",
authorization: authorization,
},
}
if (method === "POST" || method === "PUT") {
fetchOptions.body = data
} else {
if (isParamsValid(data)) {
let test = ""
for (const [key, value] of Object.entries(data)) {
test += `&${key}=${value}`
}
url += `?${test}`
}
url += `?${test}`
}
}