initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { NextResponse, type NextRequest } from 'next/server';
|
||||
import { getSupabaseAdmin } from '@/lib/supabase/admin';
|
||||
import { validateSubdomain } from '@/lib/validation';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const sub = req.nextUrl.searchParams.get('subdomain');
|
||||
const v = validateSubdomain(sub);
|
||||
if (!v.ok) {
|
||||
return NextResponse.json(
|
||||
{ available: false, error: v.error },
|
||||
{ status: 200 },
|
||||
);
|
||||
}
|
||||
const admin = getSupabaseAdmin();
|
||||
const { data, error } = await admin
|
||||
.from('tunnels')
|
||||
.select('user_id')
|
||||
.eq('subdomain', v.value)
|
||||
.maybeSingle<{ user_id: string }>();
|
||||
if (error) {
|
||||
return NextResponse.json({ available: false }, { status: 500 });
|
||||
}
|
||||
return NextResponse.json({ available: !data });
|
||||
}
|
||||
Reference in New Issue
Block a user