chatbot-template/app/actions.ts

24 lines
557 B
TypeScript
Raw Normal View History

2023-05-19 12:33:56 -04:00
"use server";
2023-05-22 10:32:06 -04:00
import { auth } from "@/auth";
2023-06-02 13:33:12 -04:00
import { chats, db } from "@/lib/db/schema";
import { and, eq } from "drizzle-orm";
2023-05-19 12:33:56 -04:00
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 12:33:56 -04:00
const userId = session?.user?.email;
if (!userId || !id) {
throw new Error("Unauthorized");
}
2023-06-02 13:33:12 -04:00
await db
.delete(chats)
.where(and(eq(chats.id, id), eq(chats.userId, userId)))
.execute();
2023-05-19 12:33:56 -04:00
revalidatePath("/");
revalidatePath("/chat/[id]");
}