feat: add delete all chats button to sidebar (#1267)
This commit is contained in:
parent
9987b25964
commit
ab402620df
3 changed files with 160 additions and 45 deletions
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue