[PR #7334] [MERGED] chore(core): use global for multiple instances of BetterAuth #15484

Closed
opened 2026-04-13 10:03:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7334
Author: @himself65
Created: 1/13/2026
Status: Merged
Merged: 1/13/2026
Merged by: @himself65

Base: canaryHead: himself65/2026/01/13/global


📝 Commits (3)

  • 251ed5f chore(core): use global for multiple instances of BetterAuth
  • 9e8ae38 Update packages/core/src/context/global.ts
  • 481e472 chore(core): use global for multiple instances of BetterAuth

📊 Changes

4 files changed (+64 additions, -43 deletions)

View changed files

📝 packages/core/src/context/endpoint-context.ts (+7 -15)
packages/core/src/context/global.ts (+43 -0)
📝 packages/core/src/context/request-state.ts (+7 -12)
📝 packages/core/src/context/transaction.ts (+7 -16)

📄 Description

Fixes: https://github.com/better-auth/better-auth/issues/7023#issuecomment-3745436014


Summary by cubic

Share AsyncLocalStorage via a process-global BetterAuth registry so multiple BetterAuth instances in the same process use the same contexts. Fixes context/transaction issues caused by duplicate packages under SSR/bundlers.

  • Refactors
    • Added getBetterAuthGlobal (global.ts) to store ALS instances in globalThis with a debug epoch counter.
    • endpoint-context, request-state, and transaction now read/write ALS from the shared global context.
    • Removed module-level symbols and local caches to avoid duplicate storages.
    • No API changes. Consistent request state and transactions across instances.

Written for commit 481e472536. 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/7334 **Author:** [@himself65](https://github.com/himself65) **Created:** 1/13/2026 **Status:** ✅ Merged **Merged:** 1/13/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2026/01/13/global` --- ### 📝 Commits (3) - [`251ed5f`](https://github.com/better-auth/better-auth/commit/251ed5fda626f727cdd87a27e8e57fa5b4020a5c) chore(core): use global for multiple instances of BetterAuth - [`9e8ae38`](https://github.com/better-auth/better-auth/commit/9e8ae382fcf5f103a3328a987f7f3becabd99a4f) Update packages/core/src/context/global.ts - [`481e472`](https://github.com/better-auth/better-auth/commit/481e472536568715beee6ebbb625f2410d395d3c) chore(core): use global for multiple instances of BetterAuth ### 📊 Changes **4 files changed** (+64 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/context/endpoint-context.ts` (+7 -15) ➕ `packages/core/src/context/global.ts` (+43 -0) 📝 `packages/core/src/context/request-state.ts` (+7 -12) 📝 `packages/core/src/context/transaction.ts` (+7 -16) </details> ### 📄 Description Fixes: https://github.com/better-auth/better-auth/issues/7023#issuecomment-3745436014 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Share AsyncLocalStorage via a process-global BetterAuth registry so multiple BetterAuth instances in the same process use the same contexts. Fixes context/transaction issues caused by duplicate packages under SSR/bundlers. - **Refactors** - Added getBetterAuthGlobal (global.ts) to store ALS instances in globalThis with a debug epoch counter. - endpoint-context, request-state, and transaction now read/write ALS from the shared global context. - Removed module-level symbols and local caches to avoid duplicate storages. - No API changes. Consistent request state and transactions across instances. <sup>Written for commit 481e472536568715beee6ebbb625f2410d395d3c. 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-13 10:03:11 -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#15484