26 lines
1 KiB
TypeScript
26 lines
1 KiB
TypeScript
// app/api/me/route.ts
|
|
import { NextResponse } from "next/server";
|
|
import { cookies } from "next/headers";
|
|
|
|
export async function GET() {
|
|
const base = process.env.NEXT_PUBLIC_API_BASE_URL!;
|
|
const url = `${base}/users/me?fields=id,display_name,first_name,last_name,email`;
|
|
|
|
// Build a Cookie header from the incoming request (preserves any other cookies you use)
|
|
const cookieHeader = cookies().getAll().map(c => `${c.name}=${c.value}`).join("; ");
|
|
|
|
// Also forward ma_at as Bearer for setups that expect token auth
|
|
const ma_at = cookies().get("ma_at")?.value;
|
|
|
|
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" },
|
|
});
|
|
}
|