build error fix
This commit is contained in:
parent
b92e6c0f82
commit
db596ad71e
1 changed files with 17 additions and 8 deletions
|
|
@ -1,18 +1,24 @@
|
|||
// app/api/me/route.ts
|
||||
import { NextResponse } from "next/server";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function GET() {
|
||||
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!;
|
||||
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("; ");
|
||||
// Forward the raw Cookie header (covers your session)…
|
||||
const cookieHeader = req.headers.get("cookie") ?? "";
|
||||
|
||||
// Also forward ma_at as Bearer for setups that expect token auth
|
||||
const ma_at = cookies().get("ma_at")?.value;
|
||||
// …and also send ma_at as Bearer for token-based setups.
|
||||
const ma_at = readCookie("ma_at", cookieHeader);
|
||||
|
||||
const headers: Record<string, string> = { "cache-control": "no-store" };
|
||||
const headers: Record<string, string> = {
|
||||
"cache-control": "no-store",
|
||||
};
|
||||
if (cookieHeader) headers.cookie = cookieHeader;
|
||||
if (ma_at) headers.authorization = `Bearer ${ma_at}`;
|
||||
|
||||
|
|
@ -21,6 +27,9 @@ export async function GET() {
|
|||
|
||||
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",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue