Scheduling infrastructure for absolutely everyone.
fix: Fix recurring booking failure due to rate limiting (#12322)
Hariom Balharae4abc8538224
diff --git a/apps/api/pages/api/bookings/_post.ts b/apps/api/pages/api/bookings/_post.tsindex aae99a031b7..062d3683d55 100644--- a/apps/api/pages/api/bookings/_post.ts+++ b/apps/api/pages/api/bookings/_post.ts@@ -205,8 +205,8 @@ import { defaultResponder } from "@calcom/lib/server";async function handler(req: NextApiRequest) {const { userId, isAdmin } = req;if (isAdmin) req.userId = req.body.userId || userId;- const booking = await handleNewBooking(req);- return booking;++ return await handleNewBooking(req);}export default defaultResponder(handler);diff --git a/apps/web/pages/api/book/event.ts b/apps/web/pages/api/book/event.tsindex 79ac39a20ce..1ca14e3a6bb 100644--- a/apps/web/pages/api/book/event.ts+++ b/apps/web/pages/api/book/event.ts@@ -2,9 +2,18 @@ import type { NextApiRequest, NextApiResponse } from "next";import { getServerSession } from "@calcom/features/auth/lib/getServerSession";import handleNewBooking from "@calcom/features/bookings/lib/handleNewBooking";+import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";+import getIP from "@calcom/lib/getIP";import { defaultResponder } from "@calcom/lib/server";async function handler(req: NextApiRequest & { userId?: number }, res: NextApiResponse) {+ const userIp = getIP(req);++ await checkRateLimitAndThrowError({+ rateLimitingType: "core",+ identifier: userIp,+ });+const session = await getServerSession({ req, res });/* To mimic API behavior and comply with types */req.userId = session?.user?.id || -1;diff --git a/apps/web/pages/api/book/recurring-event.ts b/apps/web/pages/api/book/recurring-event.tsindex b1242cce1dd..3d1566411a9 100644--- a/apps/web/pages/api/book/recurring-event.ts+++ b/apps/web/pages/api/book/recurring-event.ts@@ -3,12 +3,20 @@ import type { NextApiRequest, NextApiResponse } from "next";import { getServerSession } from "@calcom/features/auth/lib/getServerSession";import handleNewBooking from "@calcom/features/bookings/lib/handleNewBooking";import type { BookingResponse, RecurringBookingCreateBody } from "@calcom/features/bookings/types";+import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";+import getIP from "@calcom/lib/getIP";import { defaultResponder } from "@calcom/lib/server";import type { AppsStatus } from "@calcom/types/Calendar";// @TODO: Didn't look at the contents of this function in order to not break old booking page.async function handler(req: NextApiRequest & { userId?: number }, res: NextApiResponse) {+ const userIp = getIP(req);++ await checkRateLimitAndThrowError({+ rateLimitingType: "core",+ identifier: userIp,+ });const data: RecurringBookingCreateBody[] = req.body;const session = await getServerSession({ req, res });const createdBookings: BookingResponse[] = [];diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.tsindex 2537730da8e..1513acd4f77 100644--- a/packages/features/bookings/lib/handleNewBooking.ts+++ b/packages/features/bookings/lib/handleNewBooking.ts@@ -51,10 +51,8 @@ import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";import { cancelScheduledJobs, scheduleTrigger } from "@calcom/features/webhooks/lib/scheduleTrigger";import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";-import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";import { getErrorFromUnknown } from "@calcom/lib/errors";-import getIP from "@calcom/lib/getIP";import getPaymentAppData from "@calcom/lib/getPaymentAppData";import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";import { HttpError } from "@calcom/lib/http-error";@@ -629,12 +627,6 @@ async function handler(}) {const { userId } = req;- const userIp = getIP(req);-- await checkRateLimitAndThrowError({- rateLimitingType: "core",- identifier: userIp,- });// handle dynamic userlet eventType =