mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-06 03:14:34 -06:00
Add simple API token check route
This commit is contained in:
22
src/pages/api/check.ts
Normal file
22
src/pages/api/check.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type {NextApiRequest, NextApiResponse} from 'next';
|
||||
import {env} from '@/env/server.mjs';
|
||||
|
||||
type StatusData = { status: ResponseStatus };
|
||||
|
||||
type ResponseStatus =
|
||||
| 'unauthorized'
|
||||
| 'success';
|
||||
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<StatusData>
|
||||
) {
|
||||
if (req.query.key != env.API_KEY) {
|
||||
// auth failed
|
||||
res.status(401).json({ status: 'unauthorized' });
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(200).json({ status: 'success'});
|
||||
}
|
||||
Reference in New Issue
Block a user