diff --git a/app/actions.ts b/app/actions.ts
index 6ce379c..b76a647 100644
--- a/app/actions.ts
+++ b/app/actions.ts
@@ -5,13 +5,22 @@ import { chats, db } from "@/lib/db/schema";
import { and, eq } from "drizzle-orm";
import { revalidatePath } from "next/cache";
-export async function removeChat({ id, path }: { id: string; path: string }) {
- const session = await auth();
+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();
- const userId = session?.user?.email;
- if (!userId || !id) {
- throw new Error("Unauthorized");
- }
+ // const userId = session?.user?.email;
+ // if (!userId || !id) {
+ // throw new Error("Unauthorized");
+ // }
await db
.delete(chats)
diff --git a/app/sidebar-item.tsx b/app/sidebar-item.tsx
index d3e1952..09cae84 100644
--- a/app/sidebar-item.tsx
+++ b/app/sidebar-item.tsx
@@ -11,10 +11,12 @@ export function SidebarItem({
title,
href,
id,
+ userId,
}: {
title: string;
href: string;
id: string;
+ userId: string;
}) {
const pathname = usePathname();
const router = useRouter();
@@ -49,7 +51,7 @@ export function SidebarItem({
onClick={(e) => {
e.preventDefault();
startTransition(() => {
- removeChat({ id, path: href }).then(() => {
+ removeChat({ id, userId, path: href }).then(() => {
router.push("/");
});
});
diff --git a/app/sidebar.tsx b/app/sidebar.tsx
index a2d55f1..0d513b9 100644
--- a/app/sidebar.tsx
+++ b/app/sidebar.tsx
@@ -98,7 +98,7 @@ async function SidebarList({ session }: { session?: Session }) {
where: eq(chats.userId, session?.user?.email || ""),
}),
// @ts-ignore
- [session?.user?.id || ""],
+ [session?.user?.email ?? ""],
{
revalidate: 3600,
}
@@ -106,6 +106,12 @@ async function SidebarList({ session }: { session?: Session }) {
)();
return results.map((c) => (
-
+
));
}
diff --git a/auth.ts b/auth.ts
index 85f3ab2..a55a7da 100644
--- a/auth.ts
+++ b/auth.ts
@@ -5,6 +5,7 @@ import { NextResponse } from "next/server";
export const {
handlers: { GET, POST },
auth,
+ CSRF_experimental,
} = NextAuth({
// @ts-ignore
providers: [GitHub],