chatbot-template/app/actions.ts
2023-05-22 10:32:06 -04:00

25 lines
515 B
TypeScript

"use server";
import { auth } from "@/auth";
import { prisma } from "@/lib/prisma";
import { revalidatePath } from "next/cache";
export async function removeChat({ id, path }: { id: string; path: string }) {
const session = await auth();
const userId = session?.user?.email;
if (!userId || !id) {
throw new Error("Unauthorized");
}
await prisma.chat.delete({
where: {
id,
// TODO: Add scoping
// userId,
},
});
revalidatePath("/");
revalidatePath("/chat/[id]");
}