Skip to content
12 changes: 8 additions & 4 deletions apps/web/lib/actions/send-otp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ export const sendOtpAction = actionClient
.action(async ({ parsedInput }) => {
const { email } = parsedInput;

const { success } = await ratelimit(2, "1 m").limit(
`send-otp:${email}:${await getIP()}`,
);
const ip = await getIP();
Comment thread
devkiran marked this conversation as resolved.
Outdated

if (!success) {
const [{ success: emailSuccess }, { success: ipSuccess }] =
await Promise.all([
ratelimit(2, "1 m").limit(`send-otp:${email}:${ip}`),
ratelimit(15, "1 h").limit(`send-otp:${ip}`),
]);

if (!emailSuccess || !ipSuccess) {
throw new Error("Too many requests. Please try again later.");
Comment thread
devkiran marked this conversation as resolved.
}

Expand Down
Loading