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.

Revert assertRateLimit migration in api/utils.ts

Cursor Agent6cf6a30af373
diff --git a/apps/web/lib/api/utils.ts b/apps/web/lib/api/utils.ts
index e8caae6776..b6d4d07fb9 100644
--- a/apps/web/lib/api/utils.ts
+++ b/apps/web/lib/api/utils.ts
@@ -1,8 +1,7 @@
import { ipAddress } from "@vercel/functions";
import { getToken } from "next-auth/jwt";
import { NextRequest } from "next/server";
-import { assertRateLimit } from "../upstash/assert-rate-limit";
-import { RATELIMIT_POLICIES } from "../upstash/ratelimit-policies";
+import { ratelimit } from "../upstash";
import { DubApiError } from "./errors";
// TODO move into `lib/api/utils/**` as individual files
@@ -31,9 +30,14 @@ export const ratelimitOrThrow = async (
});
if (!session?.email) {
const ip = ipAddress(req);
- await assertRateLimit({
- policy: RATELIMIT_POLICIES.anonymousIpRequest,
- identifier: [identifier || "ratelimit", ip ?? ""],
- });
+ const { success } = await ratelimit().limit(
+ `${identifier || "ratelimit"}:${ip}`,
+ );
+ if (!success) {
+ throw new DubApiError({
+ code: "rate_limit_exceeded",
+ message: "Don't DDoS me pls 🥺",
+ });
+ }
}
};
diff --git a/apps/web/lib/upstash/ratelimit-policies.ts b/apps/web/lib/upstash/ratelimit-policies.ts
index 66c157ebd3..0255cea9ce 100644
--- a/apps/web/lib/upstash/ratelimit-policies.ts
+++ b/apps/web/lib/upstash/ratelimit-policies.ts
@@ -317,14 +317,6 @@ export const RATELIMIT_POLICIES = {
"You've reached the maximum number of attempts for the past 24 hours. Please wait and try again later.",
},
- // Unauthenticated IP requests (metatags, qr, providers, etc.)
- anonymousIpRequest: {
- attempts: 10,
- window: "10 s",
- keyPrefix: "rl:anonymous",
- message: "Don't DDoS me pls 🥺",
- },
-
domainSearchAvailability: {
attempts: 1,
window: "5 s",