chatbot-template/app/actions.ts

33 lines
666 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";
2023-06-02 14:28:05 -04:00
export async function removeChat({
id,
path,
userId,
}: {
id: string;
userId: string;
path: string;
}) {
// @todo next-auth doesn't work in server actions yet
// const session = await auth();
2023-06-02 14:28:05 -04:00
// const userId = session?.user?.email;
// if (!userId || !id) {
// throw new Error("Unauthorized");
// }
2023-05-19 12:33:56 -04:00
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]");
}