'me' api fix for detecting users
This commit is contained in:
parent
e6c37d0b14
commit
b92e6c0f82
1 changed files with 14 additions and 4 deletions
|
|
@ -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<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" },
|
||||
headers: { "content-type": "application/json", "cache-control": "no-store" },
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue