Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add rate limit create referral token endpoint

Kiran Kfaca4a699539
diff --git a/apps/web/lib/referrals/create-referral-token.ts b/apps/web/lib/referrals/create-referral-token.ts
index 9d5563f396..d9ca2649ac 100644
--- a/apps/web/lib/referrals/create-referral-token.ts
+++ b/apps/web/lib/referrals/create-referral-token.ts
@@ -1,6 +1,7 @@
import { prisma } from "@/lib/prisma";
import { nanoid } from "@dub/utils";
import { DubApiError } from "../api/errors";
+import { ratelimit } from "../upstash";
import {
EMBED_PUBLIC_TOKEN_EXPIRY,
EMBED_PUBLIC_TOKEN_LENGTH,
@@ -27,6 +28,15 @@ export const createReferralPublicToken = async ({
});
}
+ const { success } = await ratelimit(10, "1 m").limit(linkId);
+
+ if (!success) {
+ throw new DubApiError({
+ code: "rate_limit_exceeded",
+ message: "Too many requests.",
+ });
+ }
+
const token = await prisma.embedPublicToken.findFirst({
where: {
linkId,