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