Users can only delete their own chats

This commit is contained in:
Jared Palmer 2023-06-02 13:33:12 -04:00
parent 09ac763958
commit a7af3107b5

View file

@ -1,7 +1,8 @@
"use server"; "use server";
import { auth } from "@/auth"; 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"; import { revalidatePath } from "next/cache";
export async function removeChat({ id, path }: { id: string; path: string }) { 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"); throw new Error("Unauthorized");
} }
await prisma.chat.delete({ await db
where: { .delete(chats)
id, .where(and(eq(chats.id, id), eq(chats.userId, userId)))
// TODO: Add scoping .execute();
// userId,
},
});
revalidatePath("/"); revalidatePath("/");
revalidatePath("/chat/[id]"); revalidatePath("/chat/[id]");