API Key Plugin: Plugin option ratelimit.enabled not used on create apikey #879

Closed
opened 2026-03-13 08:08:34 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @ismael-iskauskas on GitHub (Mar 19, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

set the option ratelimit.enabled = false in betterauth plugin config

create an apikey from the client. rateLimitEnabled is true in table apikey

Current vs. Expected behavior

expected rateLimitEnabled === false in table apikey
current rateLimitEnabled === true

Solution:
in file packages/better-auth/src/plugins/api-key/routes/create-api-key.ts
line 271 change

rateLimitEnabled: rateLimitEnabled ?? true

to

rateLimitEnabled: rateLimitEnabled ?? opts.rateLimit.enabled ?? true

What version of Better Auth are you using?

1.2.4

Provide environment information

doesent matter

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
plugins: [
      openAPI({}),
      admin(),
      apiKey({
        schema: {
          apikey: {
            modelName: 'auth.api_keys',
            fields: {},
          },
        },
        rateLimit: {
          enabled: false,
          maxRequests: 1000,
          timeWindow: 1000 * 60,
        },
      }),
      twoFactor({
        schema: {
          twoFactor: {
            modelName: 'auth.two_factors',
            fields: {},
          },
        },
      }),
    ],
});

Additional context

No response

Originally created by @ismael-iskauskas on GitHub (Mar 19, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce set the option ratelimit.enabled = false in betterauth plugin config create an apikey from the client. rateLimitEnabled is true in table apikey ### Current vs. Expected behavior expected rateLimitEnabled === false in table apikey current rateLimitEnabled === true Solution: in file packages/better-auth/src/plugins/api-key/routes/create-api-key.ts line 271 change ``` ts rateLimitEnabled: rateLimitEnabled ?? true ``` to ``` ts rateLimitEnabled: rateLimitEnabled ?? opts.rateLimit.enabled ?? true ``` ### What version of Better Auth are you using? 1.2.4 ### Provide environment information ```bash doesent matter ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, plugins: [ openAPI({}), admin(), apiKey({ schema: { apikey: { modelName: 'auth.api_keys', fields: {}, }, }, rateLimit: { enabled: false, maxRequests: 1000, timeWindow: 1000 * 60, }, }), twoFactor({ schema: { twoFactor: { modelName: 'auth.two_factors', fields: {}, }, }, }), ], }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:08:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#879