fix for lens/source submission bugs
This commit is contained in:
parent
aa56de71c0
commit
d181e4dc27
4 changed files with 533 additions and 99 deletions
|
|
@ -8,24 +8,21 @@ function readCookie(name: string, cookieHeader: string) {
|
|||
|
||||
export async function GET(req: Request) {
|
||||
const base = process.env.NEXT_PUBLIC_API_BASE_URL!;
|
||||
// include username so the form can show it
|
||||
const url = `${base}/users/me?fields=id,username,display_name,first_name,last_name,email`;
|
||||
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}`;
|
||||
if (cookieHeader) headers.cookie = cookieHeader; // session cookie
|
||||
if (ma_at) headers.authorization = `Bearer ${ma_at}`; // direct token (if present)
|
||||
|
||||
const res = await fetch(url, { headers, cache: "no-store" });
|
||||
const body = await res.json().catch(() => ({}));
|
||||
const res = await fetch(url, { headers, cache: "no-store" });
|
||||
const raw = await res.json().catch(() => ({}));
|
||||
const data = raw?.data ?? raw ?? null; // normalize
|
||||
|
||||
return new NextResponse(JSON.stringify(body), {
|
||||
status: res.status,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"cache-control": "no-store",
|
||||
},
|
||||
});
|
||||
return NextResponse.json(
|
||||
{ data },
|
||||
{ status: res.status, headers: { "content-type": "application/json", "cache-control": "no-store" } }
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue