[PR #8170] [MERGED] fix: dynamic base url auth context should contain all properties of context #24692

Closed
opened 2026-04-15 22:31:00 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8170
Author: @Engerim
Created: 2/26/2026
Status: Merged
Merged: 2/27/2026
Merged by: @himself65

Base: canaryHead: fix/auth-context-contains-internal-adapter


📝 Commits (2)

  • 8544ac0 fix(auth): dynamic base url auth context should contain all properties of context
  • eb0f11f * fix linting issues

📊 Changes

2 files changed (+55 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/auth/base.ts (+4 -1)
📝 packages/better-auth/src/auth/full.test.ts (+51 -0)

📄 Description

Object.create(ctx) creates a new object with ctx as its prototype. Properties like internalAdapter, adapter, logger, secret, etc. live on the prototype -- they are not own properties. in toAuthEndpoints method the context for each endpoint is built by spreading the handler context and only the own enumerable properties are copied.

I added also a test case to check that behaviour, with my fix it is now working, I came across by testing the beta with anonymous plugin which stopped working.


Summary by cubic

Fixes per-request auth context for dynamic base URLs so endpoints and plugins receive the full context (e.g., internalAdapter, adapter, logger). Prevents missing properties when the handler context is spread.

  • Bug Fixes
    • Clone context with Object.create(Object.getPrototypeOf(ctx), Object.getOwnPropertyDescriptors(ctx)) to preserve own properties and prototype methods while isolating per-request baseURL changes.
    • Added a test that resolves the baseURL from headers and verifies internalAdapter is available in endpoint context; also fixed lint warnings (no behavior change).

Written for commit eb0f11fdb2. Summary will update 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/8170 **Author:** [@Engerim](https://github.com/Engerim) **Created:** 2/26/2026 **Status:** ✅ Merged **Merged:** 2/27/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/auth-context-contains-internal-adapter` --- ### 📝 Commits (2) - [`8544ac0`](https://github.com/better-auth/better-auth/commit/8544ac04b299cb3dba1df9af5d1c9f58c435c9fe) fix(auth): dynamic base url auth context should contain all properties of context - [`eb0f11f`](https://github.com/better-auth/better-auth/commit/eb0f11fdb2039ff431be2308ba71fb9472ebd0a5) * fix linting issues ### 📊 Changes **2 files changed** (+55 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/auth/base.ts` (+4 -1) 📝 `packages/better-auth/src/auth/full.test.ts` (+51 -0) </details> ### 📄 Description Object.create(ctx) creates a new object with ctx as its prototype. Properties like internalAdapter, adapter, logger, secret, etc. live on the prototype -- they are not own properties. in `toAuthEndpoints` method the context for each endpoint is built by spreading the handler context and only the own enumerable properties are copied. I added also a test case to check that behaviour, with my fix it is now working, I came across by testing the beta with anonymous plugin which stopped working. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes per-request auth context for dynamic base URLs so endpoints and plugins receive the full context (e.g., internalAdapter, adapter, logger). Prevents missing properties when the handler context is spread. - **Bug Fixes** - Clone context with Object.create(Object.getPrototypeOf(ctx), Object.getOwnPropertyDescriptors(ctx)) to preserve own properties and prototype methods while isolating per-request baseURL changes. - Added a test that resolves the baseURL from headers and verifies internalAdapter is available in endpoint context; also fixed lint warnings (no behavior change). <sup>Written for commit eb0f11fdb2039ff431be2308ba71fb9472ebd0a5. Summary will update 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-15 22:31:00 -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#24692