Fixes after changing api names

This commit is contained in:
2024-07-25 22:16:16 -05:00
parent a849b065a1
commit 8a00507431
2 changed files with 11 additions and 7 deletions

View File

@@ -1,17 +1,21 @@
"use server";
import { NextResponse } from 'next/server';
import { getHistory } from '~/server/functions';
import { auth } from '~/auth';
export const GET = async (request: Request) => {
try {
const url = new URL(request.url);
const apiKey = url.searchParams.get('apikey');
const page = Number(url.searchParams.get('page')) || 1;
if (apiKey !== process.env.API_KEY)
return NextResponse.json(
{ message: 'Unauthorized' },
{ status: 401 }
);
if (apiKey !== process.env.API_KEY) {
const session = await auth();
if (!session)
return NextResponse.json(
{ message: 'Unauthorized' },
{ status: 401 }
);
}
const perPage = 50;
const historyData = await getHistory(page, perPage);
return NextResponse.json(historyData, { status: 200 });