Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas-github-acc committed Jul 29, 2024
1 parent 6a22e7f commit 5102362
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/app/api/rest/v1/isUsername/route.ts
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 });
}
}

0 comments on commit 5102362

Please sign in to comment.