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

Kiran K5be976e854bd
diff --git a/apps/web/app/app.dub.co/(auth)/login/signin-email-password.tsx b/apps/web/app/app.dub.co/(auth)/login/signin-email-password.tsx
index 6d82cd086c..e8c588cf46 100644
--- a/apps/web/app/app.dub.co/(auth)/login/signin-email-password.tsx
+++ b/apps/web/app/app.dub.co/(auth)/login/signin-email-password.tsx
@@ -14,6 +14,7 @@ const errorCodes = {
"invalid-credentials": "Email or password is incorrect.",
"exceeded-login-attempts":
"Account has been locked due to too many login attempts. Please contact support to unlock your account.",
+ "too-many-login-attempts": "Too many login attempts. Please try again later.",
};
export const SignInWithEmailPassword = () => {
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index 1deb71e594..2aeca68924 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -18,6 +18,7 @@ import { dub } from "../dub";
import { subscribe } from "../flodesk";
import { isStored, storage } from "../storage";
import { UserProps } from "../types";
+import { ratelimit } from "../upstash";
import {
exceededLoginAttemptsThreshold,
incrementLoginAttempts,
@@ -208,8 +209,13 @@ export const authOptions: NextAuthOptions = {
throw new Error("no-credentials");
}
- // TODO:
- // Rate limit login attempts by IP address or email
+ const { success } = await ratelimit(5, "1 m").limit(
+ `login-attempts:${email}`,
+ );
+
+ if (!success) {
+ throw new Error("too-many-login-attempts");
+ }
const user = await prisma.user.findUnique({
where: { email },