Files
peworkshop/app/api/hunt/route.js

28 lines
851 B
JavaScript

import { getServerSession } from "next-auth/next";
import { authOptions } from "../auth/[...nextauth]/route";
import { run } from "@/lib/db";
export async function POST() {
// Removed unused 'request' parameter
const session = await getServerSession(authOptions);
if (!session || session.user.role !== "admin") {
return new Response(JSON.stringify({ error: "Unauthorized" }), {
status: 401,
});
}
try {
// Add a WHERE clause or provide an ID if you're updating a specific hunt record
await run("UPDATE hunts SET active = 1, start_time = NOW() WHERE id = ?", [
1,
]);
return new Response(JSON.stringify({ success: true }), { status: 200 });
} catch (err) {
console.error("Hunt start error:", err);
return new Response(JSON.stringify({ error: err.message }), {
status: 500,
});
}
}