[PR #3538] [MERGED] Fix: rate limit model should be default #30474

Closed
opened 2026-04-17 21:33:17 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3538
Author: @dkendrick
Created: 7/22/2025
Status: Merged
Merged: 7/22/2025
Merged by: @Bekacru

Base: mainHead: patch-1


📝 Commits (1)

  • c04864d Fix: model name needs to be default name

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/api/rate-limiter/index.ts (+1 -1)

📄 Description

I was mistaken a previous fix, it just moved the error rather than fixing the problem.

I think this value should be the default model name to match transformInput schema lookup.

My schema looks like this

{
   ...
        rateLimit: {
          modelName: 'rateLimits',
          fields: {
            key: [Object],
            count: [Object],
            lastRequest: [Object],
            id: [Object]
          }
        }
      }

Matching on the default name returns the correct schema.

This test is now passing locally a different rateLimiter model.

            it ( "should hit rate limit on forth login attempt within 10s", async () => {

                for ( let i = 0; i < 3; i++ ) {

                    const response = await request( testApp )
                        .post( usernameSignInPath )
                        .send( { username: testUsername, password: testPassword } );

                    expect( response.statusCode ).toEqual( 200 );

                }

                const res = await request( testApp )
                    .post( usernameSignInPath )
                    .send( { username: testUsername, password: testPassword } );

                expect( res.statusCode ).toEqual( 429 );
                expect( res.headers ).toHaveProperty( "x-retry-after" );

            } );

Summary by cubic

Set the rate limiter to always use the default "rateLimit" model name to ensure correct schema matching and prevent errors.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3538 **Author:** [@dkendrick](https://github.com/dkendrick) **Created:** 7/22/2025 **Status:** ✅ Merged **Merged:** 7/22/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `patch-1` --- ### 📝 Commits (1) - [`c04864d`](https://github.com/better-auth/better-auth/commit/c04864d80128271dd8acac30a4e04387ef98afd6) Fix: model name needs to be default name ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/rate-limiter/index.ts` (+1 -1) </details> ### 📄 Description I was mistaken a [previous fix](https://github.com/better-auth/better-auth/commit/452069aed976f3f06bd3f94d0d51cc74449ad9e3), it just moved the error rather than fixing the problem. I think this value should be the default model name to match [transformInput](https://github.com/better-auth/better-auth/blob/76c90f2e59b99c6d84b30ca0d3bc82cc0644ef2f/packages/better-auth/src/adapters/create-adapter/index.ts#L324) schema lookup. My schema looks like this ``` { ... rateLimit: { modelName: 'rateLimits', fields: { key: [Object], count: [Object], lastRequest: [Object], id: [Object] } } } ``` Matching on the default name returns the correct schema. This test is now passing locally a different rateLimiter model. ``` it ( "should hit rate limit on forth login attempt within 10s", async () => { for ( let i = 0; i < 3; i++ ) { const response = await request( testApp ) .post( usernameSignInPath ) .send( { username: testUsername, password: testPassword } ); expect( response.statusCode ).toEqual( 200 ); } const res = await request( testApp ) .post( usernameSignInPath ) .send( { username: testUsername, password: testPassword } ); expect( res.statusCode ).toEqual( 429 ); expect( res.headers ).toHaveProperty( "x-retry-after" ); } ); ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Set the rate limiter to always use the default "rateLimit" model name to ensure correct schema matching and prevent errors. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 21:33:17 -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#30474