diff --git a/src/app/api/get_paginated_history/route.ts b/src/app/api/get_paginated_history/route.ts index df60508..a49fd84 100644 --- a/src/app/api/get_paginated_history/route.ts +++ b/src/app/api/get_paginated_history/route.ts @@ -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 }); diff --git a/src/server/functions.ts b/src/server/functions.ts index df494e1..2e8c6f2 100644 --- a/src/server/functions.ts +++ b/src/server/functions.ts @@ -56,7 +56,7 @@ export const updateEmployeeStatusByName = interface HistoryEntry { name: string; status: string; - time: Date; + updatedAt: Date; } interface PaginatedHistory { data: HistoryEntry[]; @@ -96,7 +96,7 @@ export const getHistory = const formattedResults: HistoryEntry[] = historyRows.map(row => ({ name: row.name, status: row.status, - time: new Date(row.updatedAt), + updatedAt: new Date(row.updatedAt), })); return { data: formattedResults,