routing fixes

This commit is contained in:
makearmy 2025-09-28 11:15:37 -04:00
parent 7f75ad7856
commit a45038241f
4 changed files with 861 additions and 512 deletions

View file

@ -1,19 +1,16 @@
// app/api/me/route.ts
import { NextResponse } from "next/server";
/** Read a cookie value from a raw Cookie header string */
function readCookie(name: string, cookieHeader: string) {
const m = cookieHeader.match(new RegExp(`(?:^|;\\s*)${name}=([^;]+)`));
return m?.[1] ?? null;
}
export async function GET(req: Request) {
// Prefer DIRECTUS_URL if present; fall back to NEXT_PUBLIC_API_BASE_URL
const base =
process.env.DIRECTUS_URL || process.env.NEXT_PUBLIC_API_BASE_URL || "";
const url = `${base.replace(/\/$/, "")}/users/me?fields=id,username,display_name,first_name,last_name,email`;
const base = process.env.NEXT_PUBLIC_API_BASE_URL!;
// NOTE: include username explicitly
const url = `${base}/users/me?fields=id,username,display_name,first_name,last_name,email`;
// Forward the incoming cookies (session), and also ma_at as Bearer (token setups)
const cookieHeader = req.headers.get("cookie") ?? "";
const ma_at = readCookie("ma_at", cookieHeader);
@ -21,7 +18,7 @@ export async function GET(req: Request) {
if (cookieHeader) headers.cookie = cookieHeader;
if (ma_at) headers.authorization = `Bearer ${ma_at}`;
const res = await fetch(url, { headers, cache: "no-store" });
const res = await fetch(url, { headers, cache: "no-store" });
const body = await res.json().catch(() => ({}));
return new NextResponse(JSON.stringify(body), {