Users can only delete their own chats
This commit is contained in:
parent
09ac763958
commit
a7af3107b5
1 changed files with 6 additions and 8 deletions
|
|
@ -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]");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue