forked from code100x/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request code100x#1455 from VineeTagarwaL-code/job-board-en…
…dpoint feat: added endpoint to access / sync users into job board
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 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 |
---|---|---|
@@ -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, | ||
}); | ||
} |