[PR #4706] [CLOSED] feat: enable db transaction during api call by default #5538

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4706
Author: @himself65
Created: 9/16/2025
Status: Closed

Base: canaryHead: himself65/2025/09/16/db-transaction


📝 Commits (1)

  • 82c6c79 feat: inject db transaction by default

📊 Changes

4 files changed (+165 additions, -156 deletions)

View changed files

📝 packages/better-auth/src/auth.ts (+17 -1)
packages/better-auth/src/context/transaction.ts (+26 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+118 -147)
📝 packages/better-auth/src/db/with-hooks.ts (+4 -8)

📄 Description

Fixes: https://github.com/better-auth/better-auth/pull/4554

Summary by cubic

Wraps all auth requests in a DB transaction and provide a request-scoped adapter context using AsyncLocalStorage. This makes writes atomic per request and lets downstream code access the active adapter without prop drilling.

  • New Features
    • Execute every request inside ctx.adapter.transaction.
    • Add AsyncLocalStorage-backed context with runWithAdapter(adapter, fn) and getCurrentAdapter().
    • Fallback when node:async_hooks is unavailable: logs a warning and runs without adapter context (getCurrentAdapter() not usable).

🔄 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/4706 **Author:** [@himself65](https://github.com/himself65) **Created:** 9/16/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `himself65/2025/09/16/db-transaction` --- ### 📝 Commits (1) - [`82c6c79`](https://github.com/better-auth/better-auth/commit/82c6c79d25072a7d36d93603dbb514074b904b30) feat: inject db transaction by default ### 📊 Changes **4 files changed** (+165 additions, -156 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/auth.ts` (+17 -1) ➕ `packages/better-auth/src/context/transaction.ts` (+26 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+118 -147) 📝 `packages/better-auth/src/db/with-hooks.ts` (+4 -8) </details> ### 📄 Description Fixes: https://github.com/better-auth/better-auth/pull/4554 <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Wraps all auth requests in a DB transaction and provide a request-scoped adapter context using AsyncLocalStorage. This makes writes atomic per request and lets downstream code access the active adapter without prop drilling. - **New Features** - Execute every request inside ctx.adapter.transaction. - Add AsyncLocalStorage-backed context with runWithAdapter(adapter, fn) and getCurrentAdapter(). - Fallback when node:async_hooks is unavailable: logs a warning and runs without adapter context (getCurrentAdapter() not usable). <!-- 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:26:26 -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#5538