-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a22e7f
commit 5102362
Showing
1 changed file
with
18 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,25 @@ | ||
import {NextRequest, NextResponse} from "next/server"; | ||
import { createClient } from "@/utils/supabase/server"; | ||
|
||
export async function POST(req: NextRequest): Promise<NextResponse> { | ||
let response = NextResponse.next({ | ||
request: { | ||
headers: req.headers, | ||
}, | ||
}) | ||
try { | ||
const supabase = createClient(); | ||
const body = await req.json(); | ||
if (!body.username) { | ||
return NextResponse.json({ error: 'username is required' }, { status: 400 }); | ||
} | ||
|
||
const body = await req.json() | ||
const { data, error } = await supabase | ||
.rpc('is_username_exist', | ||
{ username: body.username } | ||
); | ||
|
||
if ( !body.username ) { | ||
return NextResponse.json({ error: 'username is required' }) | ||
} | ||
if (error) { | ||
return NextResponse.json({ error: error.message }, { status: 500 }); | ||
} | ||
|
||
let res = await fetch(`${process.env.NEXT_PUBLIC_SUPABASE_URL}/rest/v1/rpc/is_username_exist`, { | ||
method: 'POST', | ||
headers: { | ||
"apikey": process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, | ||
"Authorization": `Bearer ${process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!}`, | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(body) | ||
}); | ||
|
||
let data = await res.json(); | ||
|
||
return NextResponse.json({ state: data }); | ||
return NextResponse.json({ state: data }, { status: 200 }); | ||
} catch (error: any) { | ||
return NextResponse.json({ error: error.message }, { status: 500 }); | ||
} | ||
} |