fix: forum user lookup handles duplicate display names

When multiple profiles share a display_name (Michael Carter, Alex
Rivera, etc.), .maybeSingle() blew up with PGRST116, returning 404.
Switched to ordered limit(1) so the earliest-created profile wins
and the route resolves deterministically.
This commit is contained in:
Ryan Salazar
2026-05-23 04:16:53 +00:00
parent ae96d71d9b
commit 93dc131a02

View File

@@ -25,6 +25,9 @@ export async function GET(
// 1) Profile — accept EITHER username OR display_name (URL-encoded).
// forum_threads/forum_replies store author_name = display_name,
// so the link in the UI uses the display name; we resolve it here.
// Multiple profiles can share a display_name (Michael Carter, Alex Rivera,
// etc.) — pick the earliest-created profile deterministically rather than
// erroring out with maybeSingle().
const decoded = decodeURIComponent(username);
let { data: profile } = await sb
.from("forum_user_profiles")
@@ -36,8 +39,9 @@ export async function GET(
.from("forum_user_profiles")
.select("*")
.eq("display_name", decoded)
.maybeSingle();
profile = r2.data;
.order("created_at", { ascending: true })
.limit(1);
profile = (r2.data && r2.data[0]) || null;
}
if (!profile) {