co2 galvo owner test

This commit is contained in:
makearmy 2025-10-01 21:06:00 -04:00
parent 2e08d68b24
commit 5257a0d2fe
3 changed files with 41 additions and 17 deletions

View file

@ -0,0 +1,14 @@
// app/api/debug/whoami/route.ts
import { NextResponse } from "next/server";
import { dxGET } from "@/lib/directus";
import { requireBearer } from "@/app/api/_lib/auth";
export async function GET(req: Request) {
try {
const bearer = requireBearer(req);
const me = await dxGET<any>("/users/me?fields=id,username", bearer);
return NextResponse.json(me, { status: 200 });
} catch (e: any) {
return NextResponse.json({ error: e?.message || "err" }, { status: e?.status ?? 500 });
}
}

View file

@ -1,23 +1,27 @@
// app/api/dx/[...path]/route.ts // app/api/dx/[...path]/route.ts
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { dxGET } from "@/lib/directus";
import { requireBearer } from "@/app/api/_lib/auth"; import { requireBearer } from "@/app/api/_lib/auth";
const BASE = (process.env.DIRECTUS_URL || "").replace(/\/$/, ""); export const runtime = "nodejs";
export async function GET(req: Request, { params }: { params: { path: string[] } }) { // GET /api/dx/<anything...>?<query>
const bearer = requireBearer(req); // Proxies to Directus using the user's ma_at, no caching.
const search = new URL(req.url).search || ""; export async function GET(
const path = params.path.join("/"); req: Request,
const url = `${BASE}/${path}${search}`; { params }: { params: { path: string[] } }
) {
const res = await fetch(url, { try {
headers: { Accept: "application/json", Authorization: `Bearer ${bearer}` }, const bearer = requireBearer(req); // <-- pulls ma_at from Cookie
cache: "no-store", const search = new URL(req.url).search; // keep original query
}); const p = `/${(params.path || []).join("/")}${search || ""}`;
const json = await dxGET<any>(p, bearer);
const body = await res.text(); return NextResponse.json(json, { status: 200 });
return new NextResponse(body, { } catch (e: any) {
status: res.status, const status = e?.status ?? 500;
headers: { "content-type": res.headers.get("content-type") || "application/json" }, return NextResponse.json(
}); { errors: [{ message: e?.message || "Directus proxy error", detail: e?.detail }] },
{ status }
);
}
} }

View file

@ -170,6 +170,12 @@ export default function CO2GalvoSettingDetailPage() {
<div> <div>
<h1 className="text-3xl font-bold mb-1">{setting.setting_title}</h1> <h1 className="text-3xl font-bold mb-1">{setting.setting_title}</h1>
{/* DEBUG: remove after verifying */}
<pre className="text-xs whitespace-pre-wrap bg-muted/30 p-2 rounded">
{JSON.stringify({ owner: setting?.owner }, null, 2)}
</pre>
<div className="space-y-1 text-sm text-muted-foreground mb-3"> <div className="space-y-1 text-sm text-muted-foreground mb-3">
<p><strong>Owner:</strong> <span>{ownerDisplay}</span></p> <p><strong>Owner:</strong> <span>{ownerDisplay}</span></p>
<p><strong>Uploader:</strong> {setting.uploader || "—"}</p> <p><strong>Uploader:</strong> {setting.uploader || "—"}</p>