From a7af3107b529d971adb72b98233c9f47ddfab12a Mon Sep 17 00:00:00 2001 From: Jared Palmer Date: Fri, 2 Jun 2023 13:33:12 -0400 Subject: [PATCH] Users can only delete their own chats --- app/actions.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/actions.ts b/app/actions.ts index cab6259..6ce379c 100644 --- a/app/actions.ts +++ b/app/actions.ts @@ -1,7 +1,8 @@ "use server"; import { auth } from "@/auth"; -import { prisma } from "@/lib/prisma"; +import { chats, db } from "@/lib/db/schema"; +import { and, eq } from "drizzle-orm"; import { revalidatePath } from "next/cache"; export async function removeChat({ id, path }: { id: string; path: string }) { @@ -12,13 +13,10 @@ export async function removeChat({ id, path }: { id: string; path: string }) { throw new Error("Unauthorized"); } - await prisma.chat.delete({ - where: { - id, - // TODO: Add scoping - // userId, - }, - }); + await db + .delete(chats) + .where(and(eq(chats.id, id), eq(chats.userId, userId))) + .execute(); revalidatePath("/"); revalidatePath("/chat/[id]");