[PR #6014] [MERGED] feat(api-key): support secondary storage #14631

Closed
opened 2026-04-13 09:33:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6014
Author: @ping-maxwell
Created: 11/16/2025
Status: Merged
Merged: 11/22/2025
Merged by: @Bekacru

Base: canaryHead: feat/api-key-secondary-storage


📝 Commits (10+)

  • 25b754e feat(api-key): support secondary storage
  • d065e2d fix: change options to storage instead
  • 8511cae feat: support various storage modes
  • 9ed42dd Merge branch 'canary' into feat/api-key-secondary-storage
  • d93e195 fix: use different cache & fallback option names
  • 826a704 chore: cleanup
  • 183d22c fix: incorrect logic and added tests
  • a04e766 fix: auto populate failing
  • 3e66048 chore: update docs
  • c185871 Merge branch 'canary' into feat/api-key-secondary-storage

📊 Changes

12 files changed (+1687 additions, -116 deletions)

View changed files

📝 docs/content/docs/plugins/api-key.mdx (+180 -0)
packages/better-auth/src/plugins/api-key/adapter.ts (+518 -0)
📝 packages/better-auth/src/plugins/api-key/api-key.test.ts (+755 -1)
📝 packages/better-auth/src/plugins/api-key/index.ts (+3 -0)
📝 packages/better-auth/src/plugins/api-key/routes/create-api-key.ts (+26 -7)
📝 packages/better-auth/src/plugins/api-key/routes/delete-api-key.ts (+32 -18)
📝 packages/better-auth/src/plugins/api-key/routes/get-api-key.ts (+10 -14)
📝 packages/better-auth/src/plugins/api-key/routes/index.ts (+2 -0)
📝 packages/better-auth/src/plugins/api-key/routes/list-api-keys.ts (+4 -10)
📝 packages/better-auth/src/plugins/api-key/routes/update-api-key.ts (+44 -25)
📝 packages/better-auth/src/plugins/api-key/routes/verify-api-key.ts (+67 -41)
📝 packages/better-auth/src/plugins/api-key/types.ts (+46 -0)

📄 Description

Store API-Keys in secondary storage

image

Support storing api keys in secondary storage.

Linear: https://linear.app/better-auth/issue/ENG-100/feat-make-api-key-support-secondary-storage

  • docs
  • tests

Summary by cubic

Adds secondary storage support for API keys with optional database fallback and auto-population to speed up lookups and simplify migrations. Includes TTL handling from expiresAt and consistent cleanup. Implements Linear ENG-100.

  • New Features
    • Storage modes: storage = "database" (default) or "secondary-storage"; optional fallbackToDatabase reads DB when missing and writes to both layers.
    • Unified keys: api-key:${hashedKey}, api-key:by-id:${id}, api-key:by-user:${userId}; TTL from expiresAt.
    • Routes updated (create/get/list/update/delete/verify) for both modes; auto-generate IDs without DB; keep user lists in sync; delete on expiry/exhaustion.
    • Custom storage: customStorage overrides global secondaryStorage for API keys.
    • Docs and tests updated for config, migration, CRUD, verify, rate limits, remaining, TTL, and custom storage.

Written for commit 0e943f0bb1. Summary will update automatically on new commits.


🔄 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/6014 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 11/16/2025 **Status:** ✅ Merged **Merged:** 11/22/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/api-key-secondary-storage` --- ### 📝 Commits (10+) - [`25b754e`](https://github.com/better-auth/better-auth/commit/25b754e7990929bb14b5ee6ca4ede2e28b9b18e6) feat(api-key): support secondary storage - [`d065e2d`](https://github.com/better-auth/better-auth/commit/d065e2d0a672a004d49a8ab3005714529428daac) fix: change options to `storage` instead - [`8511cae`](https://github.com/better-auth/better-auth/commit/8511cae52694b1915485fc8dc26e668b4ca5490a) feat: support various storage modes - [`9ed42dd`](https://github.com/better-auth/better-auth/commit/9ed42dd325ca7fb6a7c6257826d5c57f4a84ab4d) Merge branch 'canary' into feat/api-key-secondary-storage - [`d93e195`](https://github.com/better-auth/better-auth/commit/d93e1955c4d2d13fbae0c689858daf32cd4d86a4) fix: use different cache & fallback option names - [`826a704`](https://github.com/better-auth/better-auth/commit/826a7047b6d6e3978475d740cc2c610a1c41ff06) chore: cleanup - [`183d22c`](https://github.com/better-auth/better-auth/commit/183d22c7d6c01a4137fd3a00f082f32eda2bd2c3) fix: incorrect logic and added tests - [`a04e766`](https://github.com/better-auth/better-auth/commit/a04e766485c69ab1c6aab9ab82bc2c6c3d216dbe) fix: auto populate failing - [`3e66048`](https://github.com/better-auth/better-auth/commit/3e660482480891ec02d50206d879691c6dcf2e39) chore: update docs - [`c185871`](https://github.com/better-auth/better-auth/commit/c1858712f97a091278796330dd17acf69b6fdad1) Merge branch 'canary' into feat/api-key-secondary-storage ### 📊 Changes **12 files changed** (+1687 additions, -116 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/api-key.mdx` (+180 -0) ➕ `packages/better-auth/src/plugins/api-key/adapter.ts` (+518 -0) 📝 `packages/better-auth/src/plugins/api-key/api-key.test.ts` (+755 -1) 📝 `packages/better-auth/src/plugins/api-key/index.ts` (+3 -0) 📝 `packages/better-auth/src/plugins/api-key/routes/create-api-key.ts` (+26 -7) 📝 `packages/better-auth/src/plugins/api-key/routes/delete-api-key.ts` (+32 -18) 📝 `packages/better-auth/src/plugins/api-key/routes/get-api-key.ts` (+10 -14) 📝 `packages/better-auth/src/plugins/api-key/routes/index.ts` (+2 -0) 📝 `packages/better-auth/src/plugins/api-key/routes/list-api-keys.ts` (+4 -10) 📝 `packages/better-auth/src/plugins/api-key/routes/update-api-key.ts` (+44 -25) 📝 `packages/better-auth/src/plugins/api-key/routes/verify-api-key.ts` (+67 -41) 📝 `packages/better-auth/src/plugins/api-key/types.ts` (+46 -0) </details> ### 📄 Description ## Store API-Keys in secondary storage <img width="2604" height="1000" alt="image" src="https://github.com/user-attachments/assets/070fb252-f04e-49e4-ade9-800bc94336bf" /> ## Support storing api keys in secondary storage. Linear: https://linear.app/better-auth/issue/ENG-100/feat-make-api-key-support-secondary-storage - [x] docs - [x] tests <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds secondary storage support for API keys with optional database fallback and auto-population to speed up lookups and simplify migrations. Includes TTL handling from expiresAt and consistent cleanup. Implements Linear ENG-100. - **New Features** - Storage modes: storage = "database" (default) or "secondary-storage"; optional fallbackToDatabase reads DB when missing and writes to both layers. - Unified keys: api-key:${hashedKey}, api-key:by-id:${id}, api-key:by-user:${userId}; TTL from expiresAt. - Routes updated (create/get/list/update/delete/verify) for both modes; auto-generate IDs without DB; keep user lists in sync; delete on expiry/exhaustion. - Custom storage: customStorage overrides global secondaryStorage for API keys. - Docs and tests updated for config, migration, CRUD, verify, rate limits, remaining, TTL, and custom storage. <sup>Written for commit 0e943f0bb169def460275d645eab32d8501057fd. Summary will update automatically on new commits.</sup> <!-- 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-13 09:33:09 -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#14631