[PR #5400] [CLOSED] fix(api-key): add server-side support to api key function calls #5981

Closed
opened 2026-03-13 12:43:36 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5400
Author: @okisdev
Created: 10/18/2025
Status: Closed

Base: canaryHead: fix(api-key)/broken-after-fix


📝 Commits (10+)

  • 8e50561 fix(api-key): broken after fix
  • 08b5b3d fix(api-key): broken after fix
  • 2dd0365 fix(api-key): broken after fix
  • c758b30 Merge branch 'canary' into fix(api-key)/broken-after-fix
  • 8503c2b Add missing email validation (#5593)
  • 77c768c Merge branch 'canary' into fix(api-key)/broken-after-fix
  • acc8c9d Merge branch 'canary' into fix(api-key)/broken-after-fix
  • 5c518bb fix(api-key): broken after fix
  • 1b3fe30 Merge branch 'canary' into fix(api-key)/broken-after-fix
  • e7b4691 Merge branch 'canary' into fix(api-key)/broken-after-fix

📊 Changes

7 files changed (+493 additions, -43 deletions)

View changed files

📝 docs/content/docs/plugins/api-key.mdx (+18 -0)
📝 packages/better-auth/src/plugins/api-key/api-key.test.ts (+381 -21)
📝 packages/better-auth/src/plugins/api-key/routes/create-api-key.ts (+1 -1)
📝 packages/better-auth/src/plugins/api-key/routes/delete-api-key.ts (+31 -8)
📝 packages/better-auth/src/plugins/api-key/routes/get-api-key.ts (+27 -7)
📝 packages/better-auth/src/plugins/api-key/routes/list-api-keys.ts (+34 -5)
📝 packages/better-auth/src/plugins/api-key/routes/update-api-key.ts (+1 -1)

📄 Description

This PR fixes Api Keys related issue in #5397 by enabling server-side calls to getApiKey, listApiKeys, and deleteApiKey endpoints with the userId parameter, completing the fix started in #5317.

fix https://github.com/better-auth/better-auth/issues/5397


Summary by cubic

Allow server-side use of API key endpoints by accepting an optional userId when headers aren’t available, fixing broken behavior. Adds strict auth checks to prevent impersonation and return correct errors. Fixes #5397.

  • Bug Fixes
    • Accept userId in getApiKey, listApiKeys, and deleteApiKey for server-side calls.
    • Use getSessionFromCtx and block impersonation; handle banned users; return UNAUTHORIZED/NOT_FOUND consistently.
    • Update docs to document server-side userId and add tests covering success and error cases.

Written for commit 8ed43869e0. 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/5400 **Author:** [@okisdev](https://github.com/okisdev) **Created:** 10/18/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix(api-key)/broken-after-fix` --- ### 📝 Commits (10+) - [`8e50561`](https://github.com/better-auth/better-auth/commit/8e5056129adf89560c48866209a8942a5a49012f) fix(api-key): broken after fix - [`08b5b3d`](https://github.com/better-auth/better-auth/commit/08b5b3d74956d5d3e3a99e381ec5810264615db9) fix(api-key): broken after fix - [`2dd0365`](https://github.com/better-auth/better-auth/commit/2dd036595b3daf7085e7a8754a55fb5bc2a414bb) fix(api-key): broken after fix - [`c758b30`](https://github.com/better-auth/better-auth/commit/c758b30a13c0eb5b1c5be0eaa18f334a860d2b5d) Merge branch 'canary' into fix(api-key)/broken-after-fix - [`8503c2b`](https://github.com/better-auth/better-auth/commit/8503c2b79f8fc9824006823f627acf7e8ad46d25) Add missing email validation (#5593) - [`77c768c`](https://github.com/better-auth/better-auth/commit/77c768c860520656d8cf0727efdd2445ed4ad1fa) Merge branch 'canary' into fix(api-key)/broken-after-fix - [`acc8c9d`](https://github.com/better-auth/better-auth/commit/acc8c9dc97fc54a5e8cc3b8db276d230e1c10bba) Merge branch 'canary' into fix(api-key)/broken-after-fix - [`5c518bb`](https://github.com/better-auth/better-auth/commit/5c518bb7517bbd5196f342f3b718be5081f4c8c6) fix(api-key): broken after fix - [`1b3fe30`](https://github.com/better-auth/better-auth/commit/1b3fe301e7dc4bd28e4130d3a76a5ef80fef7f92) Merge branch 'canary' into fix(api-key)/broken-after-fix - [`e7b4691`](https://github.com/better-auth/better-auth/commit/e7b469160a0a46f7f88f7dab88fcf9fea13a1724) Merge branch 'canary' into fix(api-key)/broken-after-fix ### 📊 Changes **7 files changed** (+493 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/api-key.mdx` (+18 -0) 📝 `packages/better-auth/src/plugins/api-key/api-key.test.ts` (+381 -21) 📝 `packages/better-auth/src/plugins/api-key/routes/create-api-key.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/api-key/routes/delete-api-key.ts` (+31 -8) 📝 `packages/better-auth/src/plugins/api-key/routes/get-api-key.ts` (+27 -7) 📝 `packages/better-auth/src/plugins/api-key/routes/list-api-keys.ts` (+34 -5) 📝 `packages/better-auth/src/plugins/api-key/routes/update-api-key.ts` (+1 -1) </details> ### 📄 Description This PR fixes Api Keys related issue in #5397 by enabling server-side calls to `getApiKey`, `listApiKeys`, and `deleteApiKey` endpoints with the `userId` parameter, completing the fix started in #5317. fix https://github.com/better-auth/better-auth/issues/5397 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Allow server-side use of API key endpoints by accepting an optional userId when headers aren’t available, fixing broken behavior. Adds strict auth checks to prevent impersonation and return correct errors. Fixes #5397. - **Bug Fixes** - Accept userId in getApiKey, listApiKeys, and deleteApiKey for server-side calls. - Use getSessionFromCtx and block impersonation; handle banned users; return UNAUTHORIZED/NOT_FOUND consistently. - Update docs to document server-side userId and add tests covering success and error cases. <sup>Written for commit 8ed43869e0a8876b881654ee6354757174f5f9f7. 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-03-13 12:43:36 -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#5981