From 0ee9686fb1b4c99bc4be663ae742402dc666057c Mon Sep 17 00:00:00 2001 From: makearmy Date: Sun, 28 Sep 2025 12:17:12 -0400 Subject: [PATCH] routing fixes --- app/api/me/route.ts | 14 +++++----- app/components/forms/SettingsSubmit.tsx | 36 ++++++++++++++++++------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/api/me/route.ts b/app/api/me/route.ts index 98535788..9975575c 100644 --- a/app/api/me/route.ts +++ b/app/api/me/route.ts @@ -8,8 +8,8 @@ function readCookie(name: string, cookieHeader: string) { export async function GET(req: Request) { const base = process.env.NEXT_PUBLIC_API_BASE_URL!; - // <- add username to the requested fields - const url = `${base}/users/me?fields=id,username,display_name,first_name,last_name,email`; + // include username here + 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); @@ -18,12 +18,14 @@ 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 text = await res.text().catch(() => ""); - let body: any; try { body = text ? JSON.parse(text) : {}; } catch { body = {}; } + 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", "cache-control": "no-store" }, + headers: { + "content-type": "application/json", + "cache-control": "no-store", + }, }); } diff --git a/app/components/forms/SettingsSubmit.tsx b/app/components/forms/SettingsSubmit.tsx index 69b05d23..93f8c340 100644 --- a/app/components/forms/SettingsSubmit.tsx +++ b/app/components/forms/SettingsSubmit.tsx @@ -33,16 +33,33 @@ function useOptions(path: string) { .then((r) => r.json()) .then((j) => { if (!alive) return; + const raw = (j?.data ?? j) as any[]; + const normalized: Opt[] = Array.isArray(raw) ? raw - .map((x) => ({ - id: String(x?.id ?? x?.value ?? x?.key ?? ""), - // recognize common label fields + 'opacity' - label: String(x?.label ?? x?.name ?? x?.title ?? x?.text ?? x?.opacity ?? ""), - })) + .map((x) => { + const id = String(x?.id ?? x?.value ?? x?.key ?? "").trim(); + + // Accept common label fields + "opacity" (string field) + let label = + (x?.label ?? + x?.name ?? + x?.title ?? + x?.text ?? + x?.opacity) as string | undefined; + + // Nice fallback for sources where you have make/model + if (!label && (x?.make || x?.model)) { + label = [x.make, x.model].filter(Boolean).join(" "); + } + + label = String(label ?? "").trim(); + return { id, label }; + }) .filter((o) => o.id && o.label) : []; + setOpts(normalized); }) .finally(() => alive && setLoading(false)); @@ -168,13 +185,12 @@ export default function SettingsSubmit({ initialTarget }: { initialTarget?: Targ }; }, []); - // Prefer username; then display_name; then full name; then email. const meLabel = - (me?.username && me.username.trim()) || - (me?.display_name && me.display_name.trim()) || + (me?.username?.trim()) || + (me?.email?.trim()) || ([me?.first_name, me?.last_name].filter(Boolean).join(" ").trim()) || - (me?.email && me.email.trim()) || - ""; + (me?.display_name?.trim()) || + (me?.id ? `User ${me.id.slice(0, 8)}…${me.id.slice(-4)}` : "Unknown user"); // Options