routing fixes
This commit is contained in:
parent
0ee9686fb1
commit
44a690f4d2
20 changed files with 769 additions and 962 deletions
|
|
@ -1,31 +0,0 @@
|
|||
// app/api/me/route.ts
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
function readCookie(name: string, cookieHeader: string) {
|
||||
const m = cookieHeader.match(new RegExp(`(?:^|;\\s*)${name}=([^;]+)`));
|
||||
return m?.[1] ?? null;
|
||||
}
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const base = process.env.NEXT_PUBLIC_API_BASE_URL!;
|
||||
// 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);
|
||||
|
||||
const headers: Record<string, string> = { "cache-control": "no-store" };
|
||||
if (cookieHeader) headers.cookie = cookieHeader;
|
||||
if (ma_at) headers.authorization = `Bearer ${ma_at}`;
|
||||
|
||||
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",
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue