diff --git a/app/api/me/route.ts b/app/api/me/route.ts index 35e5bd77..9d8f09a4 100644 --- a/app/api/me/route.ts +++ b/app/api/me/route.ts @@ -8,18 +8,13 @@ function readCookie(name: string, cookieHeader: string) { export async function GET(req: Request) { const base = process.env.NEXT_PUBLIC_API_BASE_URL!; - // ⬇️ include username + // include username so the form can show it const url = `${base}/users/me?fields=id,username,display_name,first_name,last_name,email`; - // Forward the raw Cookie header (covers your session)… const cookieHeader = req.headers.get("cookie") ?? ""; - - // …and also send ma_at as Bearer for token-based setups. const ma_at = readCookie("ma_at", cookieHeader); - const headers: Record = { - "cache-control": "no-store", - }; + const headers: Record = { "cache-control": "no-store" }; if (cookieHeader) headers.cookie = cookieHeader; if (ma_at) headers.authorization = `Bearer ${ma_at}`; diff --git a/app/components/forms/SettingsSubmit.tsx b/app/components/forms/SettingsSubmit.tsx index 7f4f4f95..0a40c14c 100644 --- a/app/components/forms/SettingsSubmit.tsx +++ b/app/components/forms/SettingsSubmit.tsx @@ -27,7 +27,18 @@ function useOptions(path: string) { fetch(url, { cache: "no-store", credentials: "include" }) .then((r) => r.json()) .then((j) => { - if (alive) setOpts((j?.data as Opt[]) ?? []); + if (!alive) return; + // Normalize to {id, label} no matter what the API returns + const raw = (j?.data ?? j) as any[]; + const normalized: Opt[] = Array.isArray(raw) + ? raw + .map((x) => ({ + id: String(x?.id ?? x?.value ?? x?.key ?? ""), + label: String(x?.label ?? x?.name ?? x?.title ?? x?.text ?? ""), + })) + .filter((o) => o.id && o.label) + : []; + setOpts(normalized); }) .finally(() => { if (alive) setLoading(false); @@ -41,7 +52,14 @@ function useOptions(path: string) { } function FilterableSelect({ - label, name, register, options, loading, onQuery, placeholder = "—", required = false, + label, + name, + register, + options, + loading, + onQuery, + placeholder = "—", + required = false, }: { label: string; name: string; @@ -53,7 +71,9 @@ function FilterableSelect({ required?: boolean; }) { const [filter, setFilter] = useState(""); - useEffect(() => { onQuery?.(filter); }, [filter, onQuery]); + useEffect(() => { + onQuery?.(filter); + }, [filter, onQuery]); const filtered = useMemo(() => { if (!filter) return options; @@ -73,18 +93,21 @@ function FilterableSelect({ onChange={(e) => setFilter(e.target.value)} /> ); } -function BoolBox({ label, name, register }:{ - label: string; name: string; register: UseFormRegister; -}) { +function BoolBox({ label, name, register }: { label: string; name: string; register: UseFormRegister }) { return (