"use server"; import { revalidatePath } from "next/cache"; import { auth } from "@/lib/auth"; import { prisma } from "@/lib/prisma"; export async function createTicket(formData: FormData): Promise { // Re-read the session user id server-side; never trust a form-supplied id. const session = await auth(); const userId = Number(session?.user?.id); if (!Number.isInteger(userId) || userId <= 0) return; const title = String(formData.get("title") ?? "").trim().slice(0, 255); const content = String(formData.get("content") ?? "").trim().slice(0, 5000); if (!title || !content) return; const now = new Date(); await prisma.websiteHelpCenterTickets.create({ data: { userId, title, content, open: true, createdAt: now, updatedAt: now, }, }); revalidatePath("/help/tickets"); }