chatbot-template/app/actions.ts

26 lines
565 B
TypeScript
Raw Normal View History

2023-05-19 12:33:56 -04:00
"use server";
import { prisma } from "@/lib/prisma";
import { getServerSession } from "@/lib/session/get-server-session";
2023-05-19 12:33:56 -04:00
import { revalidatePath } from "next/cache";
export async function removeChat({ id, path }: { id: string; path: string }) {
const session = await getServerSession();
2023-05-19 12:33:56 -04:00
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]");
}