[PR #4083] [MERGED] fix: check x-api-key for all auth endpoint #22077

Closed
opened 2026-04-15 20:48:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4083
Author: @himself65
Created: 8/19/2025
Status: Merged
Merged: 8/20/2025
Merged by: @himself65

Base: canaryHead: himself65/2025/08/19/fix-api-key


📝 Commits (2)

📊 Changes

2 files changed (+82 additions, -30 deletions)

View changed files

📝 packages/better-auth/src/plugins/api-key/api-key.test.ts (+49 -0)
📝 packages/better-auth/src/plugins/api-key/index.ts (+33 -30)

📄 Description

Fixes: https://github.com/better-auth/better-auth/issues/4080


Summary by cubic

Always set the session context when authenticating with an API key, not just for /get-session. Fixes API key requests failing on other endpoints and enables using x-api-key across the API.

  • Bug Fixes
    • Set ctx.context.session for all API key–authenticated requests after user validation.
    • Keep /get-session behavior (returns session) while other endpoints now work with API key auth.
    • Added tests: authenticate with x-api-key on list/verify endpoints and ensure session context is set.

🔄 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/4083 **Author:** [@himself65](https://github.com/himself65) **Created:** 8/19/2025 **Status:** ✅ Merged **Merged:** 8/20/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/08/19/fix-api-key` --- ### 📝 Commits (2) - [`7d8d998`](https://github.com/better-auth/better-auth/commit/7d8d99863e08bb0ffe49124b1a91262fb7003ecf) fix: api key is not available - [`f2ef268`](https://github.com/better-auth/better-auth/commit/f2ef26889aa6dde23f9f29e106ce164c509c0c46) fix: lint ### 📊 Changes **2 files changed** (+82 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/api-key/api-key.test.ts` (+49 -0) 📝 `packages/better-auth/src/plugins/api-key/index.ts` (+33 -30) </details> ### 📄 Description Fixes: https://github.com/better-auth/better-auth/issues/4080 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Always set the session context when authenticating with an API key, not just for /get-session. Fixes API key requests failing on other endpoints and enables using x-api-key across the API. - **Bug Fixes** - Set ctx.context.session for all API key–authenticated requests after user validation. - Keep /get-session behavior (returns session) while other endpoints now work with API key auth. - Added tests: authenticate with x-api-key on list/verify endpoints and ensure session context is set. <!-- 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-15 20:48:10 -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#22077