Skip to content

Commit

Permalink
little changes to api/isUsername
Browse files Browse the repository at this point in the history
minor changes
  • Loading branch information
Anas-github-acc authored Jul 30, 2024
1 parent fd608db commit 3191142
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 });
}
}

1 comment on commit 3191142

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for iiitvcc ready!

✅ Preview
https://iiitvcc-4devneggw-iiitv-coding-clubs-projects.vercel.app

Built with commit 3191142.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.