Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions app/[username]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { notFound } from 'next/navigation';
import { PublicProfileView } from "@/components/users/PublicProfileView";
import { reservedUsernameService } from '@/lib/services/reserved-usernames';
import { createClient } from '@/lib/supabase/server';
import Header from "@/components/header";
import Footer from "@/components/footer";

Expand All @@ -26,8 +27,26 @@ export default async function UsernamePage({ params }: UsernamePageProps) {
}
}

// For now, treat all non-reserved usernames as profile routes
// In the future, this could be expanded to handle other username-based routes
// Check if the username actually exists in the database
try {
const supabase = await createClient();
const { data: profile, error } = await supabase
.from('profiles')
.select('id, username, is_public')
.eq('username', username)
.eq('is_public', true)
.single();

// If there's an error or no profile found, show 404
if (error || !profile) {
notFound();
}
} catch (error) {
// If there's any error, show 404
notFound();
}

Comment on lines +30 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

⚠️ Potential issue

Differentiate β€œnot found” from real errors; don’t mask 500s as 404s.

Use maybeSingle() and only 404 on null; throw other errors so the error boundary renders 500.

Apply:

-  // Check if the username actually exists in the database
-  try {
-    const supabase = await createClient();
-    const { data: profile, error } = await supabase
-      .from('profiles')
-      .select('id, username, is_public')
-      .eq('username', username)
-      .eq('is_public', true)
-      .single();
-    
-    // If there's an error or no profile found, show 404
-    if (error || !profile) {
-      notFound();
-    }
-  } catch (error) {
-    // If there's any error, show 404
-    notFound();
-  }
+  // Check if the username actually exists in the database
+  const supabase = await createClient();
+  const { data: profile, error } = await supabase
+    .from('profiles')
+    .select('id, username, is_public')
+    .eq('username', username)
+    .eq('is_public', true)
+    .maybeSingle();
+  if (error) {
+    throw error; // surfaces as 500
+  }
+  if (!profile) {
+    notFound();
+  }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Check if the username actually exists in the database
try {
const supabase = await createClient();
const { data: profile, error } = await supabase
.from('profiles')
.select('id, username, is_public')
.eq('username', username)
.eq('is_public', true)
.single();
// If there's an error or no profile found, show 404
if (error || !profile) {
notFound();
}
} catch (error) {
// If there's any error, show 404
notFound();
}
// Check if the username actually exists in the database
const supabase = await createClient();
const { data: profile, error } = await supabase
.from('profiles')
.select('id, username, is_public')
.eq('username', username)
.eq('is_public', true)
.maybeSingle();
if (error) {
throw error; // surfaces as 500
}
if (!profile) {
notFound();
}
πŸ€– Prompt for AI Agents
In app/[username]/page.tsx around lines 30 to 48, the current try/catch masks
real server errors by always returning a 404; change the DB call to use
maybeSingle() instead of single(), check only for a null profile and call
notFound() in that case, and let any other errors propagate (remove the catch or
rethrow the caught error) so the error boundary can render a 500; ensure you
still call createClient() and surface any supabase error by throwing it instead
of converting it to a 404.

// If we get here, the username exists and is public
return (
<>
<Header />
Expand Down
Loading
Loading