routing fixes

This commit is contained in:
makearmy 2025-09-28 12:17:12 -04:00
parent a490471e4f
commit 0ee9686fb1
2 changed files with 34 additions and 16 deletions

View file

@ -8,8 +8,8 @@ function readCookie(name: string, cookieHeader: string) {
export async function GET(req: Request) {
const base = process.env.NEXT_PUBLIC_API_BASE_URL!;
// <- add username to the requested fields
const url = `${base}/users/me?fields=id,username,display_name,first_name,last_name,email`;
// include username here
const url = `${base}/users/me?fields=id,username,display_name,first_name,last_name,email`;
const cookieHeader = req.headers.get("cookie") ?? "";
const ma_at = readCookie("ma_at", cookieHeader);
@ -18,12 +18,14 @@ export async function GET(req: Request) {
if (cookieHeader) headers.cookie = cookieHeader;
if (ma_at) headers.authorization = `Bearer ${ma_at}`;
const res = await fetch(url, { headers, cache: "no-store" });
const text = await res.text().catch(() => "");
let body: any; try { body = text ? JSON.parse(text) : {}; } catch { body = {}; }
const res = await fetch(url, { headers, cache: "no-store" });
const body = await res.json().catch(() => ({}));
return new NextResponse(JSON.stringify(body), {
status: res.status,
headers: { "content-type": "application/json", "cache-control": "no-store" },
headers: {
"content-type": "application/json",
"cache-control": "no-store",
},
});
}