[PR #4777] [MERGED] fix(api-key): calling client on server side #5574

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

📋 Pull Request Information

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

Base: canaryHead: himself65/2025/09/19/api-key


📝 Commits (2)

📊 Changes

2 files changed (+87 additions, -2 deletions)

View changed files

e2e/smoke/test/ssr.ts (+76 -0)
📝 packages/better-auth/src/api/to-auth-endpoints.ts (+11 -2)

📄 Description

Fixes: https://github.com/better-auth/better-auth/issues/3588
Fixes: https://github.com/better-auth/better-auth/issues/4698

Summary by cubic

Fixes server-side usage of the auth client with API keys by correctly handling endpoint “before” responses. Adds an SSR test to cover createAuthClient with a custom fetch and x-api-key.

  • Bug Fixes
    • Wrap before-hook results based on asResponse/returnHeaders and preserve headers in toResponse to unblock server-side client calls.
    • Added SSR smoke test: create user, issue API key, and call getSession with x-api-key via createAuthClient.

🔄 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/4777 **Author:** [@himself65](https://github.com/himself65) **Created:** 9/19/2025 **Status:** ✅ Merged **Merged:** 9/19/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/09/19/api-key` --- ### 📝 Commits (2) - [`04ebb41`](https://github.com/better-auth/better-auth/commit/04ebb412edfb4d5a2e2541a27ae380ab50134c34) fix: calling client on server side - [`8685f21`](https://github.com/better-auth/better-auth/commit/8685f21f123df4b17ba318b42e8cff6d729d98f8) fix: debugger ### 📊 Changes **2 files changed** (+87 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `e2e/smoke/test/ssr.ts` (+76 -0) 📝 `packages/better-auth/src/api/to-auth-endpoints.ts` (+11 -2) </details> ### 📄 Description Fixes: https://github.com/better-auth/better-auth/issues/3588 Fixes: https://github.com/better-auth/better-auth/issues/4698 <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Fixes server-side usage of the auth client with API keys by correctly handling endpoint “before” responses. Adds an SSR test to cover createAuthClient with a custom fetch and x-api-key. - **Bug Fixes** - Wrap before-hook results based on asResponse/returnHeaders and preserve headers in toResponse to unblock server-side client calls. - Added SSR smoke test: create user, issue API key, and call getSession with x-api-key via createAuthClient. <!-- 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:28:06 -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#5574