Add api to get users for initial app start

This commit is contained in:
2024-09-09 23:03:48 -05:00
parent 28f44c35c6
commit c8cb5d16d1
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,21 @@
'use server';
import { NextResponse } from 'next/server';
import { getUsers } from '~/server/functions';
export const GET = async (request: Request) => {
try {
const url = new URL(request.url);
const apiKey = url.searchParams.get('apiKey');
if (apiKey !== process.env.API_KEY) {
console.log('Invalid API Key');
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
} else {
const users = await getUsers();
return NextResponse.json(users);
}
} catch (error) {
console.error(error);
return NextResponse.json({ message: "Error" }, { status: 500 });
}
};
// localhost:3000/api/getUsers?apiKey=I_Love_Madeline