Skip to content
Open
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
8 changes: 8 additions & 0 deletions app/api/username/check/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
import { validateUsername } from "@/lib/validations/username";
import { isReservedUsername } from '@/lib/reservedUsernames';

async function isAvailable(username: string): Promise<boolean> {
const [user, alias] = await Promise.all([
Expand All @@ -11,6 +12,13 @@ async function isAvailable(username: string): Promise<boolean> {
return !user && !alias;
}

if (isReservedUsername(username)) {
return NextResponse.json(
{ available: false, reason: 'This username is reserved and cannot be claimed.' },
{ status: 200 } // return 200 so the UI can show the message without erroring
);
}

export async function GET(req: Request) {
const { searchParams } = new URL(req.url);
const username = searchParams.get("username")?.toLowerCase();
Expand Down
21 changes: 21 additions & 0 deletions lib/reservedUsernames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// lib/reservedUsernames.ts
export const RESERVED_USERNAMES = new Set([
// App Router path conflicts
'api', 'app', 'auth', '_next',
// Admin paths
'admin', 'administrator', 'root', 'superuser', 'moderator',
// Auth routes
'login', 'logout', 'register', 'signup', 'signin', 'signout',
'callback', 'verify', 'reset', 'forgot', 'onboarding',
// Dashboard routes
'dashboard', 'settings', 'profile', 'account',
// Brand reserved
'linkid', 'support', 'help', 'docs', 'blog', 'about',
'contact', 'terms', 'privacy', 'security', 'status',
// Generic abuse targets
'null', 'undefined', 'anonymous', 'test', 'demo', 'example',
]);

export function isReservedUsername(username: string): boolean {
return RESERVED_USERNAMES.has(username.toLowerCase().trim());
}
Loading