fix(botid): re-add bot protection to demo branch (#1445)

This commit is contained in:
dancer 2026-03-04 19:20:57 +00:00 committed by GitHub
parent 99cd8699c1
commit 3bc77653ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 45 additions and 11 deletions

View file

@ -1,3 +1,4 @@
import { checkBotId } from "botid/server";
import { geolocation, ipAddress } from "@vercel/functions";
import {
convertToModelMessages,
@ -64,7 +65,10 @@ export async function POST(request: Request) {
const { id, message, messages, selectedChatModel, selectedVisibilityType } =
requestBody;
const session = await auth();
const [, session] = await Promise.all([
checkBotId().catch(() => null),
auth(),
]);
if (!session?.user) {
return new ChatbotError("unauthorized:chat").toResponse();
@ -80,10 +84,10 @@ export async function POST(request: Request) {
const messageCount = await getMessageCountByUserId({
id: session.user.id,
differenceInHours: 24,
differenceInHours: 1,
});
if (messageCount > entitlementsByUserType[userType].maxMessagesPerDay) {
if (messageCount > entitlementsByUserType[userType].maxMessagesPerHour) {
return new ChatbotError("rate_limit:chat").toResponse();
}