Switch to @vercel/kv
This commit is contained in:
parent
45d3a8d0ee
commit
fc79a708f4
20 changed files with 188 additions and 1079 deletions
|
|
@ -1,8 +1,6 @@
|
|||
"use server";
|
||||
|
||||
import { auth } from "@/auth";
|
||||
import { chats, db } from "@/lib/db/schema";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { kv } from "@vercel/kv";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function removeChat({
|
||||
|
|
@ -14,18 +12,15 @@ export async function removeChat({
|
|||
userId: string;
|
||||
path: string;
|
||||
}) {
|
||||
// @todo next-auth doesn't work in server actions yet
|
||||
// @todo next-auth@v5 doesn't work in server actions yet
|
||||
// const session = await auth();
|
||||
|
||||
// const userId = session?.user?.email;
|
||||
// if (!userId || !id) {
|
||||
// throw new Error("Unauthorized");
|
||||
// }
|
||||
|
||||
await db
|
||||
.delete(chats)
|
||||
.where(and(eq(chats.id, id), eq(chats.userId, userId)))
|
||||
.execute();
|
||||
const uid = await kv.hget<string>(`chat:${id}`, "userId");
|
||||
if (uid !== userId) {
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
await kv.del(`chat:${id}`);
|
||||
await kv.zrem(`user:chat:${userId}`, `chat:${id}`);
|
||||
|
||||
revalidatePath("/");
|
||||
revalidatePath("/chat/[id]");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue