[PR #3648] [MERGED] Fix API key remaining initialization issue #30534

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3648
Author: @eaoliver
Created: 7/27/2025
Status: Merged
Merged: 8/1/2025
Merged by: @Bekacru

Base: mainHead: bug/apikey-remaining-fix


📝 Commits (7)

  • 6db8c80 Fixes #3640 - Resolves issue related to incorrect initialization of remaining value within API key.
  • 3bd62ac Adding test cases for fix of #3640.
  • 3fdb573 Merge branch 'main' into bug/apikey-remaining-fix
  • 1728339 Merge branch 'main' into bug/apikey-remaining-fix
  • 400b331 Merge branch 'main' into bug/apikey-remaining-fix
  • 93b70ca Merge branch 'main' into bug/apikey-remaining-fix
  • b48f173 chore: update changeset

📊 Changes

3 files changed (+73 additions, -1 deletions)

View changed files

.changeset/salty-banks-heal.md (+5 -0)
📝 packages/better-auth/src/plugins/api-key/api-key.test.ts (+66 -0)
📝 packages/better-auth/src/plugins/api-key/routes/create-api-key.ts (+2 -1)

📄 Description

Minor bug fix to Closes #3640 related to the re-initialization of the remaining property of an API key. The existing code was ignoring the user and default value of null and changing it to the value of refillAmount.

Additional tests added, which are consistent with documentation. All tests pass. No updates to documentation.


Summary by cubic

Fixed an issue where creating an API key with remaining set to null would incorrectly assign a usage cap, instead of allowing unlimited usage as intended.

  • Bug Fixes
    • Corrected API key creation logic to respect null values for remaining.
    • Added tests to cover cases with null, zero, and undefined remaining values.

🔄 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/3648 **Author:** [@eaoliver](https://github.com/eaoliver) **Created:** 7/27/2025 **Status:** ✅ Merged **Merged:** 8/1/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `bug/apikey-remaining-fix` --- ### 📝 Commits (7) - [`6db8c80`](https://github.com/better-auth/better-auth/commit/6db8c804426c439959e4de269e48974bb6f34d00) Fixes #3640 - Resolves issue related to incorrect initialization of remaining value within API key. - [`3bd62ac`](https://github.com/better-auth/better-auth/commit/3bd62acf444effe242bdff589b1be33611eb7ecc) Adding test cases for fix of #3640. - [`3fdb573`](https://github.com/better-auth/better-auth/commit/3fdb573c85f5004e0139728b8e8f0e348b2f82ef) Merge branch 'main' into bug/apikey-remaining-fix - [`1728339`](https://github.com/better-auth/better-auth/commit/1728339a951ac47eb7f37292d6fcd24c77d9af12) Merge branch 'main' into bug/apikey-remaining-fix - [`400b331`](https://github.com/better-auth/better-auth/commit/400b3313f57c2f58153bfe3b54b2ee11126cc48d) Merge branch 'main' into bug/apikey-remaining-fix - [`93b70ca`](https://github.com/better-auth/better-auth/commit/93b70cafc9563dee957716405730f525f5148177) Merge branch 'main' into bug/apikey-remaining-fix - [`b48f173`](https://github.com/better-auth/better-auth/commit/b48f173c30a967c1b4929292be1a23765365e1f5) chore: update changeset ### 📊 Changes **3 files changed** (+73 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/salty-banks-heal.md` (+5 -0) 📝 `packages/better-auth/src/plugins/api-key/api-key.test.ts` (+66 -0) 📝 `packages/better-auth/src/plugins/api-key/routes/create-api-key.ts` (+2 -1) </details> ### 📄 Description Minor bug fix to Closes #3640 related to the re-initialization of the `remaining` property of an API key. The existing code was ignoring the user and default value of `null` and changing it to the value of `refillAmount`. Additional tests added, which are consistent with documentation. All tests pass. No updates to documentation. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed an issue where creating an API key with remaining set to null would incorrectly assign a usage cap, instead of allowing unlimited usage as intended. - **Bug Fixes** - Corrected API key creation logic to respect null values for remaining. - Added tests to cover cases with null, zero, and undefined remaining values. <!-- 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:35: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#30534