Skip to content

Commit 477202b

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

5 files changed

Lines changed: 37 additions & 3 deletions

File tree

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

Lines changed: 5 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,10 @@ export async function POST(request: Request) {
6465
const { id, message, messages, selectedChatModel, selectedVisibilityType } =
6566
requestBody;
6667

67-
const session = await auth();
68+
const [, session] = await Promise.all([
69+
checkBotId().catch(() => null),
70+
auth(),
71+
]);
6872

6973
if (!session?.user) {
7074
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);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@xyflow/react": "^12.10.0",
5050
"ai": "6.0.37",
5151
"bcrypt-ts": "^5.0.2",
52+
"botid": "^1.5.11",
5253
"class-variance-authority": "^0.7.1",
5354
"classnames": "^2.5.1",
5455
"clsx": "^2.1.1",

pnpm-lock.yaml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)