mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-06 03:14:34 -06:00
Use unauthorized helper function in each API route, remote unused 'center' constant
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
import type {NextApiRequest, NextApiResponse} from 'next';
|
||||
import {env} from '@/env/server.mjs';
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { unauthorized } from '@/utils/helpers';
|
||||
|
||||
type StatusData = { status: ResponseStatus };
|
||||
|
||||
type ResponseStatus =
|
||||
| 'unauthorized'
|
||||
| 'success';
|
||||
|
||||
type ResponseStatus = 'unauthorized' | 'success';
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<StatusData>
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<StatusData>
|
||||
) {
|
||||
if (req.query.key != env.API_KEY) {
|
||||
// auth failed
|
||||
res.status(401).json({ status: 'unauthorized' });
|
||||
return;
|
||||
}
|
||||
if (unauthorized(req, res)) return;
|
||||
|
||||
res.status(200).json({ status: 'success'});
|
||||
res.status(200).json({ status: 'success' });
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { env } from '@/env/server.mjs';
|
||||
import { fetchConfiguration, setConfiguration } from '@/db';
|
||||
import { Configuration, ConfigurationSchema } from '@/timing';
|
||||
import { unauthorized } from '@/utils/helpers';
|
||||
|
||||
type StatusData = { status: ResponseStatus };
|
||||
|
||||
@@ -11,11 +11,7 @@ export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<StatusData | Configuration>
|
||||
) {
|
||||
if (req.query.key != env.API_KEY) {
|
||||
// auth failed
|
||||
res.status(401).json({ status: 'unauthorized' });
|
||||
return;
|
||||
}
|
||||
if (unauthorized(req, res)) return;
|
||||
|
||||
if (req.method == 'GET') {
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { getMatchingTime } from '@/timing';
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getDistance } from '@/location';
|
||||
import { env } from '@/env/server.mjs';
|
||||
import monitorAsync from '@/monitor';
|
||||
import { sendNotification } from '@/notify';
|
||||
import {
|
||||
@@ -32,11 +31,6 @@ type ResponseStatus =
|
||||
| 'notified'
|
||||
| 'error';
|
||||
|
||||
const center = {
|
||||
latitude: env.CENTER_LATITUDE,
|
||||
longitude: env.CENTER_LONGITUDE
|
||||
};
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<(ResponseData & StatusData) | StatusData>
|
||||
|
||||
Reference in New Issue
Block a user