How to add allowedAttempts for sendOTP #3865
-
|
In the current |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
|
Yes, better-auth has a built-in way to rate-limit the sendOTP endpoint. You can use the global rateLimit configuration with customRules to restrict how often a user can request an OTP. For your use case (max 1 request per 5 minutes), add this to your betterAuth config: rateLimit: {
enabled: true,
customRules: {
"/phone-number/send-otp": {
window: 300, // 5 minutes in seconds
max: 1,
},
},
// For distributed/serverless setups, set storage: "database" or "secondary-storage"
}This will limit each IP to one OTP request per 5 minutes on that endpoint. By default, rate limiting is IP+path-based, but you can customize the storage logic for per-user limits if needed. Rate limiting only applies to client-initiated requests, not server-side calls via To reply, just mention @dosu. Docs are dead. Just use Dosu. |
Beta Was this translation helpful? Give feedback.
-
|
@dosu Thanks for the answer! I’ve configured rate limiting for the Configuration: rateLimit: {
enabled: true,
window: 10,
max: 3,
customRules: {
"/phone-number/send-otp": {
window: 300, // 5 min
max: 1,
},
},
},A phone number should be blocked from requesting another OTP for 5 minutes after the first attempt, regardless of page refreshes. Is there a misconfiguration? |
Beta Was this translation helpful? Give feedback.
Yes, better-auth has a built-in way to rate-limit the sendOTP endpoint. You can use the global rateLimit configuration with customRules to restrict how often a user can request an OTP. For your use case (max 1 request per 5 minutes), add this to your betterAuth config:
This will limit each IP to one OTP request per 5 minutes on that endpoint. By default, rate limiting is IP+path-based, but you can customize the storage logic for per-user limits if needed.…