From f07964090d9a0630723b13b174881af1d4e9476d Mon Sep 17 00:00:00 2001 From: VineeTagarwaL-code Date: Mon, 7 Oct 2024 23:59:12 +0530 Subject: [PATCH] feat: added endpoint to access / sync users into job board --- src/app/api/user/exists/route.ts | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/app/api/user/exists/route.ts diff --git a/src/app/api/user/exists/route.ts b/src/app/api/user/exists/route.ts new file mode 100644 index 000000000..9254e8926 --- /dev/null +++ b/src/app/api/user/exists/route.ts @@ -0,0 +1,33 @@ +import { type NextRequest, NextResponse } from 'next/server'; +import db from '@/db'; + +export async function GET(req: NextRequest) { + const url = new URL(req.url); + + const apiKey = url.searchParams.get('apiKey'); + const email = url.searchParams.get('email'); + if (!apiKey) { + return NextResponse.json({ message: 'No token provided' }, { status: 400 }); + } + if (apiKey !== process.env.JOB_BOARD_AUTH_SECRET) { + return NextResponse.json({ message: 'Invalid token' }, { status: 400 }); + } + const user = await db.user.findFirst({ + where: { + email, + }, + select: { + purchases: true, + email: true, + id: true, + name: true, + certificate: true, + }, + }); + if (!user) { + return NextResponse.json({ message: 'User not found' }, { status: 404 }); + } + return NextResponse.json({ + user, + }); +}