Want help to use rate limiting for a custom Route : /api/form

I’m building a simple form with no login or signup. I want to add rate limiting to one specific API route, but I’m stuck. I read the docs, but it’s not working. Can someone help me set up rate limiting for that route?
4 Replies
Timur
Timur4w ago
Mind sharing your auth config? The docs is pretty forward on how to rate limit one route https://www.better-auth.com/docs/reference/options#ratelimit
Options | Better Auth
Better Auth configuration options reference.
kartik
kartikOP4w ago
import { betterAuth } from "better-auth"; export const auth = betterAuth({ user: { additionalFields: { phoneNumber: { type: "string", required: false, }, pincode: { type: "string", required: false, }, }, }, rateLimit: { enabled: true, window: 60, max: 100, storage: "memory", customRules: { "/api/form": { window: 60, max: 5, }, }, }, advanced: { ipAddress: { ipAddressHeaders: ["x-forwarded-for", "x-real-ip", "cf-connecting-ip"], }, }, });
Timur
Timur4w ago
How do you know it is not working? How did u test it?
kartik
kartikOP4w ago
I was just sending request one by one , around 10 request and all requests were successful

Did you find this page helpful?