Skip to content
Discussion options

You must be logged in to vote

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.…

Replies: 2 comments 11 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by MaksimPrudnikau
Comment options

You must be logged in to vote
11 replies
@dosubot
Comment options

@MaksimPrudnikau
Comment options

@dosubot
Comment options

@MaksimPrudnikau
Comment options

@dosubot
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant