From de5b8d2e5e1cf897f210098bdbc7d6014965ca32 Mon Sep 17 00:00:00 2001 From: Shahriar <31452340+ShahriarKh@users.noreply.github.com> Date: Sun, 23 Mar 2025 16:13:43 +0330 Subject: [PATCH 1/2] Update rate-limit.mdx add `enabled: true` --- docs/content/docs/concepts/rate-limit.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/content/docs/concepts/rate-limit.mdx b/docs/content/docs/concepts/rate-limit.mdx index 1f3036aa0c..18bd337424 100644 --- a/docs/content/docs/concepts/rate-limit.mdx +++ b/docs/content/docs/concepts/rate-limit.mdx @@ -15,6 +15,7 @@ import { betterAuth } from "better-auth"; export const auth = betterAuth({ rateLimit: { + enabled: true, window: 10, // time window in seconds max: 100, // max requests in the window }, @@ -39,6 +40,7 @@ import { betterAuth } from "better-auth"; export const auth = betterAuth({ //...other options rateLimit: { + enabled: true, window: 60, // time window in seconds max: 100, // max requests in the window }, @@ -53,6 +55,7 @@ import { betterAuth } from "better-auth"; export const auth = betterAuth({ //...other options rateLimit: { + enabled: true, window: 60, // time window in seconds max: 100, // max requests in the window customRules: { @@ -86,6 +89,7 @@ export const auth = betterAuth({ rateLimit: { storage: "database", modelName: "rateLimit", //optional by default "rateLimit" is used + enabled: true }, }) ``` @@ -202,4 +206,4 @@ Table Name: `rateLimit` type: "bigint", description: "Max requests in the window" }]} - /> \ No newline at end of file + /> From c3bd98202964dc4cb8637dee969e239551a27ec6 Mon Sep 17 00:00:00 2001 From: Shahriar <31452340+ShahriarKh@users.noreply.github.com> Date: Tue, 25 Mar 2025 00:22:32 +0330 Subject: [PATCH 2/2] Update rate-limit.mdx --- docs/content/docs/concepts/rate-limit.mdx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/content/docs/concepts/rate-limit.mdx b/docs/content/docs/concepts/rate-limit.mdx index 18bd337424..9daf768790 100644 --- a/docs/content/docs/concepts/rate-limit.mdx +++ b/docs/content/docs/concepts/rate-limit.mdx @@ -15,13 +15,23 @@ import { betterAuth } from "better-auth"; export const auth = betterAuth({ rateLimit: { - enabled: true, window: 10, // time window in seconds max: 100, // max requests in the window }, }) ``` +Rate limiting is disabled in development mode by default. In order to enable it, set `enabled` to `true`: + +```ts title="auth.ts" +export const auth = betterAuth({ + rateLimit: { + enabled: true, + //...other options + }, +}) +``` + In addition to the default settings, Better Auth provides custom rules for specific paths. For example: - `/sign-in/email`: Is limited to 3 requests within 10 seconds. @@ -40,7 +50,6 @@ import { betterAuth } from "better-auth"; export const auth = betterAuth({ //...other options rateLimit: { - enabled: true, window: 60, // time window in seconds max: 100, // max requests in the window }, @@ -55,7 +64,6 @@ import { betterAuth } from "better-auth"; export const auth = betterAuth({ //...other options rateLimit: { - enabled: true, window: 60, // time window in seconds max: 100, // max requests in the window customRules: { @@ -89,7 +97,6 @@ export const auth = betterAuth({ rateLimit: { storage: "database", modelName: "rateLimit", //optional by default "rateLimit" is used - enabled: true }, }) ```