From 93dc131a02b8d0f5009f7acadcd522d86cce14c0 Mon Sep 17 00:00:00 2001 From: Ryan Salazar Date: Sat, 23 May 2026 04:16:53 +0000 Subject: [PATCH] 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. --- src/app/api/forum/user-by-username/[username]/route.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/api/forum/user-by-username/[username]/route.ts b/src/app/api/forum/user-by-username/[username]/route.ts index a70950a..61ac981 100644 --- a/src/app/api/forum/user-by-username/[username]/route.ts +++ b/src/app/api/forum/user-by-username/[username]/route.ts @@ -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) {