From b92e6c0f82fb457e82b729f1eac07aaaf2be630c Mon Sep 17 00:00:00 2001 From: makearmy Date: Sun, 28 Sep 2025 01:54:33 -0400 Subject: [PATCH] 'me' api fix for detecting users --- app/api/me/route.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/api/me/route.ts b/app/api/me/route.ts index a89a79fc..d8cd5235 100644 --- a/app/api/me/route.ts +++ b/app/api/me/route.ts @@ -1,16 +1,26 @@ // app/api/me/route.ts import { NextResponse } from "next/server"; +import { cookies } from "next/headers"; -export async function GET(req: Request) { - const cookie = req.headers.get("cookie") || ""; +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`; - const res = await fetch(url, { headers: { cookie }, cache: "no-store" }); + // 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 = { "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" }, + headers: { "content-type": "application/json", "cache-control": "no-store" }, }); }