Skip to content

Commit bb0f184

Browse files
author
Deepak Pandey
committed
feat: Add custom 404 page with funny messages and fix username routing
- Add custom not-found.tsx with rotating funny messages for developers - Fix username routing to show 404 for non-existent users - Remove mini-game to keep 404 page minimal and clean - Messages change on page refresh for variety - Proper error handling for username existence checks
1 parent e606400 commit bb0f184

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

app/[username]/page.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { notFound } from 'next/navigation';
22
import { PublicProfileView } from "@/components/users/PublicProfileView";
33
import { reservedUsernameService } from '@/lib/services/reserved-usernames';
4+
import { createClient } from '@/lib/supabase/server';
45
import Header from "@/components/header";
56
import Footer from "@/components/footer";
67

@@ -26,8 +27,26 @@ export default async function UsernamePage({ params }: UsernamePageProps) {
2627
}
2728
}
2829

29-
// For now, treat all non-reserved usernames as profile routes
30-
// In the future, this could be expanded to handle other username-based routes
30+
// Check if the username actually exists in the database
31+
try {
32+
const supabase = await createClient();
33+
const { data: profile, error } = await supabase
34+
.from('profiles')
35+
.select('id, username, is_public')
36+
.eq('username', username)
37+
.eq('is_public', true)
38+
.single();
39+
40+
// If there's an error or no profile found, show 404
41+
if (error || !profile) {
42+
notFound();
43+
}
44+
} catch (error) {
45+
// If there's any error, show 404
46+
notFound();
47+
}
48+
49+
// If we get here, the username exists and is public
3150
return (
3251
<>
3352
<Header />

app/not-found.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"use client"
2+
3+
import Link from "next/link"
4+
import { Button } from "@/components/ui/button"
5+
import { Home, ArrowLeft } from "lucide-react"
6+
7+
// Simple 404 messages
8+
const funnyMessages = [
9+
"Oops, you've gone off the grid 🚀",
10+
"This page doesn't exist… yet 👨‍💻",
11+
"Error 404: Opportunity Not Found",
12+
"This page is in another branch 🌿",
13+
"This page is taking a coffee break ☕",
14+
"This route is still under development 😜",
15+
"Lost? Even Stack Overflow can't help you here 🤷‍♂️"
16+
]
17+
18+
export default function NotFound() {
19+
// Pick a random message on each page load
20+
const randomMessage = funnyMessages[Math.floor(Math.random() * funnyMessages.length)]
21+
22+
return (
23+
<div className="min-h-screen bg-gradient-to-br from-background via-background to-muted/20 flex items-center justify-center p-4">
24+
<div className="max-w-2xl mx-auto text-center">
25+
<div className="mb-8">
26+
<h1 className="text-8xl md:text-9xl font-bold text-primary/20 mb-6 select-none">
27+
404
28+
</h1>
29+
<h2 className="text-2xl font-semibold text-foreground mb-4">
30+
Page Not Found
31+
</h2>
32+
<p className="text-lg text-primary font-medium mb-8">
33+
{randomMessage}
34+
</p>
35+
</div>
36+
37+
<div className="flex flex-col sm:flex-row gap-4 justify-center">
38+
<Button asChild size="lg" className="bg-primary hover:bg-primary/90">
39+
<Link href="/">
40+
<Home className="h-4 w-4 mr-2" />
41+
Take me Home
42+
</Link>
43+
</Button>
44+
<Button asChild variant="outline" size="lg">
45+
<Link href="/events">
46+
<ArrowLeft className="h-4 w-4 mr-2" />
47+
Back to Events
48+
</Link>
49+
</Button>
50+
</div>
51+
</div>
52+
</div>
53+
)
54+
}

0 commit comments

Comments
 (0)