Skip to content

Commit 0b045b5

Browse files
committed
fix(botid): re-add bot protection to demo branch
1 parent 99cd869 commit 0b045b5

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

app/(chat)/api/chat/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { checkBotId } from "botid/server";
12
import { geolocation, ipAddress } from "@vercel/functions";
23
import {
34
convertToModelMessages,
@@ -64,7 +65,11 @@ export async function POST(request: Request) {
6465
const { id, message, messages, selectedChatModel, selectedVisibilityType } =
6566
requestBody;
6667

67-
const session = await auth();
68+
const [botResult, session] = await Promise.all([checkBotId(), auth()]);
69+
70+
if (botResult.isBot) {
71+
return new ChatbotError("unauthorized:chat").toResponse();
72+
}
6873

6974
if (!session?.user) {
7075
return new ChatbotError("unauthorized:chat").toResponse();

instrumentation-client.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
export {};
1+
import { initBotId } from "botid/client/core";
2+
3+
initBotId({
4+
protect: [
5+
{
6+
path: "/api/chat",
7+
method: "POST",
8+
},
9+
],
10+
});

next.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { withBotId } from "botid/next/config";
12
import type { NextConfig } from "next";
23

34
const basePath = "/demo";
@@ -24,4 +25,4 @@ const nextConfig: NextConfig = {
2425
},
2526
};
2627

27-
export default nextConfig;
28+
export default withBotId(nextConfig);

0 commit comments

Comments
 (0)