username notice fix

This commit is contained in:
makearmy 2025-09-28 07:04:42 -04:00
parent db596ad71e
commit ab639edc7a
2 changed files with 10 additions and 6 deletions

View file

@ -8,7 +8,8 @@ function readCookie(name: string, cookieHeader: string) {
export async function GET(req: Request) {
const base = process.env.NEXT_PUBLIC_API_BASE_URL!;
const url = `${base}/users/me?fields=id,display_name,first_name,last_name,email`;
// ⬇️ include username
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") ?? "";
@ -22,7 +23,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), {

View file

@ -8,6 +8,7 @@ type Target = "settings_fiber" | "settings_co2gan" | "settings_co2gal" | "settin
type Opt = { id: string; label: string };
type Me = {
id: string;
username?: string;
display_name?: string;
first_name?: string;
last_name?: string;
@ -119,12 +120,14 @@ export default function SettingsSubmit({ initialTarget }: { initialTarget?: Targ
return () => { alive = false; };
}, []);
const shortId = (s?: string) => (s ? `${s.slice(0, 8)}${s.slice(-4)}` : "");
const meLabel =
me?.display_name ||
(me?.username ? `@${me.username}` : "") ||
(me?.display_name || "").trim() ||
[me?.first_name, me?.last_name].filter(Boolean).join(" ").trim() ||
me?.email ||
me?.id ||
"";
(me?.email ? me.email.split("@")[0] : "") ||
(me?.id ? `User ${shortId(me.id)}` : "");
// Generic lists (alphabetical)
const mats = useOptions("material");