[PR #4730] [MERGED] fix(org): use correct adapter during db tranaction #5553

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

📋 Pull Request Information

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

Base: canaryHead: himself65/2025/09/17/org


📝 Commits (3)

📊 Changes

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

View changed files

📝 packages/better-auth/src/plugins/organization/adapter.ts (+38 -1)
packages/better-auth/src/plugins/organization/organization-hook.test.ts (+310 -0)

📄 Description

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


Summary by cubic

Use the active, transaction-aware adapter in the organization plugin so all org/team/member operations run inside the current DB transaction. Adds tests to verify hook-driven org creation works and rolls back on errors. Fixes better-auth/better-auth#4718.

  • Bug Fixes
    • Resolve adapter from async context via getCurrentAdapter in all organization adapter methods.
    • Ensure org creation and membership writes inside user create hooks share the same transaction and rollback on failure.
    • Added tests covering: after/before user hooks, duplicate-slug rollback, and multiple async steps within the same transaction.

🔄 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/4730 **Author:** [@himself65](https://github.com/himself65) **Created:** 9/17/2025 **Status:** ✅ Merged **Merged:** 9/17/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/09/17/org` --- ### 📝 Commits (3) - [`8223afc`](https://github.com/better-auth/better-auth/commit/8223afc710b45444dc39ab8e0f0ed214f360d2f5) fix(org): get db adapter from async storage - [`bb1d36f`](https://github.com/better-auth/better-auth/commit/bb1d36f64c3660b8387b4ad532db002192d6c115) test: db - [`4bfa6f1`](https://github.com/better-auth/better-auth/commit/4bfa6f18a7b464811faa24ddf42e97eedf3d88dd) chore: lint fix ### 📊 Changes **2 files changed** (+348 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+38 -1) ➕ `packages/better-auth/src/plugins/organization/organization-hook.test.ts` (+310 -0) </details> ### 📄 Description Fixes: https://github.com/better-auth/better-auth/issues/4718 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Use the active, transaction-aware adapter in the organization plugin so all org/team/member operations run inside the current DB transaction. Adds tests to verify hook-driven org creation works and rolls back on errors. Fixes better-auth/better-auth#4718. - **Bug Fixes** - Resolve adapter from async context via getCurrentAdapter in all organization adapter methods. - Ensure org creation and membership writes inside user create hooks share the same transaction and rollback on failure. - Added tests covering: after/before user hooks, duplicate-slug rollback, and multiple async steps within the same transaction. <!-- 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:27:17 -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#5553