import { getServerSession } from "next-auth/next"; import { authOptions } from "../auth/[...nextauth]/route"; import { run } from "@/lib/db"; export async function POST(request) { 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]); // Or if you just have one hunt record: "UPDATE hunts SET active = 1, start_time = NOW()" return new Response(JSON.stringify({ success: true }), { status: 200 }); } catch (err) { console.error("Hunt start error:", err); // Add logging for better debugging return new Response(JSON.stringify({ error: err.message }), { status: 500, }); } }