fixes create to now check for author before creating game system
This commit is contained in:
parent
729aba68ce
commit
5f2243b49a
@ -1,11 +1,23 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
|
import { auth } from "@/auth";
|
||||||
import { prisma } from "@/prisma/prismaClient";
|
import { prisma } from "@/prisma/prismaClient";
|
||||||
|
|
||||||
export const createGameSystem = async (name: string) => {
|
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({
|
const { id } = await prisma.gameSystem.create({
|
||||||
data: {
|
data: {
|
||||||
name,
|
name,
|
||||||
|
authorId: session.user.id,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
import { prisma } from "@/prisma/prismaClient";
|
"use client";
|
||||||
|
import { createGameSystem } from "@/actions/GameSystems/create";
|
||||||
|
import { useToast } from "@/components/toast";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export default function CreateGameSystem() {
|
export default function CreateGameSystem() {
|
||||||
|
const { createToast } = useToast();
|
||||||
async function create(form: FormData) {
|
async function create(form: FormData) {
|
||||||
"use server";
|
|
||||||
|
|
||||||
const name = form.get("name")?.toString();
|
const name = form.get("name")?.toString();
|
||||||
if (!name) return;
|
if (!name)
|
||||||
const { id } = await prisma.gameSystem.create({
|
return createToast({ msg: "Please provide a name", fading: true });
|
||||||
data: {
|
createToast({ msg: "Creating Game System", fading: true });
|
||||||
name,
|
const id = await createGameSystem(name);
|
||||||
},
|
if (!id)
|
||||||
select: {
|
return createToast({
|
||||||
id: true,
|
msg: "Issue creating game system. Is your email verified?",
|
||||||
},
|
fading: true,
|
||||||
|
type: "error",
|
||||||
});
|
});
|
||||||
redirect(`/game-systems/${id}`);
|
redirect(`/game-systems/${id}`);
|
||||||
}
|
}
|
||||||
@ -22,7 +24,6 @@ export default function CreateGameSystem() {
|
|||||||
<form action={create}>
|
<form action={create}>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
// {...bind}
|
|
||||||
name="name"
|
name="name"
|
||||||
placeholder="Create a new game system..."
|
placeholder="Create a new game system..."
|
||||||
className="w-min"
|
className="w-min"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user