diff --git a/actions/GameSystems/create.ts b/actions/GameSystems/create.ts index bb5bf9e..ba845a6 100644 --- a/actions/GameSystems/create.ts +++ b/actions/GameSystems/create.ts @@ -1,11 +1,23 @@ "use server"; +import { auth } from "@/auth"; import { prisma } from "@/prisma/prismaClient"; export const createGameSystem = async (name: string) => { + const session = await auth(); + if (!session?.user?.id) return null; + + const user = await prisma.user.findFirst({ + where: { id: session.user.id }, + select: { emailVerified: true }, + }); + + if (!user?.emailVerified) return null; + const { id } = await prisma.gameSystem.create({ data: { name, + authorId: session.user.id, }, select: { id: true, diff --git a/app/game-systems/create.tsx b/app/game-systems/create.tsx index f55a2a1..bcbbfb7 100644 --- a/app/game-systems/create.tsx +++ b/app/game-systems/create.tsx @@ -1,20 +1,22 @@ -import { prisma } from "@/prisma/prismaClient"; +"use client"; +import { createGameSystem } from "@/actions/GameSystems/create"; +import { useToast } from "@/components/toast"; import { redirect } from "next/navigation"; export default function CreateGameSystem() { + const { createToast } = useToast(); async function create(form: FormData) { - "use server"; - const name = form.get("name")?.toString(); - if (!name) return; - const { id } = await prisma.gameSystem.create({ - data: { - name, - }, - select: { - id: true, - }, - }); + if (!name) + return createToast({ msg: "Please provide a name", fading: true }); + createToast({ msg: "Creating Game System", fading: true }); + const id = await createGameSystem(name); + if (!id) + return createToast({ + msg: "Issue creating game system. Is your email verified?", + fading: true, + type: "error", + }); redirect(`/game-systems/${id}`); } @@ -22,7 +24,6 @@ export default function CreateGameSystem() {