feat: add delete all chats button to sidebar (#1267)

This commit is contained in:
josh 2025-10-09 18:51:17 +01:00 committed by GitHub
parent 9987b25964
commit ab402620df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 160 additions and 45 deletions

View file

@ -1,6 +1,6 @@
import type { NextRequest } from "next/server";
import { auth } from "@/app/(auth)/auth";
import { getChatsByUserId } from "@/lib/db/queries";
import { getChatsByUserId, deleteAllChatsByUserId } from "@/lib/db/queries";
import { ChatSDKError } from "@/lib/errors";
export async function GET(request: NextRequest) {
@ -32,3 +32,15 @@ export async function GET(request: NextRequest) {
return Response.json(chats);
}
export async function DELETE() {
const session = await auth();
if (!session?.user) {
return new ChatSDKError("unauthorized:chat").toResponse();
}
const result = await deleteAllChatsByUserId({ userId: session.user.id });
return Response.json(result, { status: 200 });
}