built user portal behind auth

This commit is contained in:
makearmy 2025-09-27 14:30:16 -04:00
parent 5c6962f4a5
commit 37d474d7c8
48 changed files with 822 additions and 496 deletions

View file

@ -0,0 +1,26 @@
export const dynamic = "force-dynamic";
import { NextRequest, NextResponse } from "next/server";
const BASE = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
const PATH = `/items/laser_focus_lens?fields=id,name&sort=name`;
export async function GET(req: NextRequest) {
try {
const userAt = req.cookies.get("ma_at")?.value;
if (!userAt) return NextResponse.json({ error: "Not authenticated" }, { status: 401 });
const res = await fetch(`${BASE}${PATH}`, {
headers: { Accept: "application/json", Authorization: `Bearer ${userAt}` },
cache: "no-store",
});
const txt = await res.text();
if (!res.ok) return NextResponse.json({ error: txt || res.statusText }, { status: res.status });
const j = txt ? JSON.parse(txt) : { data: [] };
const data = (j.data ?? []).map(({ id, name }: any) => ({ id, name }));
return NextResponse.json({ data });
} catch (e: any) {
return NextResponse.json({ error: e?.message || "Failed to load focus lenses" }, { status: 500 });
}
}