[PR #4560] [CLOSED] refactor(admin): use transactions #31048

Closed
opened 2026-04-17 21:59:43 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4560
Author: @jslno
Created: 9/10/2025
Status: Closed

Base: canaryHead: chore/admin-transactions


📝 Commits (7)

  • 20a0d18 feat(internal-adapter): add withTransaction helper
  • 2a4370b chore: update init snapshot
  • 8a70767 chore: cleanup
  • b58a506 fix: shim appended to wrong parameter
  • 1e03d48 fix: preserve generics
  • d290e16 chore: remove unused import
  • f78bbf0 chore(admin): use transactions

📊 Changes

4 files changed (+171 additions, -82 deletions)

View changed files

📝 packages/better-auth/src/__snapshots__/init.test.ts.snap (+1 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+60 -39)
📝 packages/better-auth/src/plugins/admin/admin.ts (+56 -43)
📝 packages/better-auth/src/utils/shim.ts (+54 -0)

📄 Description

Related: #4554


Summary by cubic

Refactored admin flows to run inside database transactions for atomic user creation and bans. Adds internalAdapter.withTransaction and a shim to inject the transaction adapter, improving consistency and preventing partial writes.

  • Refactors
    • Admin: user creation + credential link now run in a single transaction; banning a user + session revocation also transactionally.
    • Internal adapter: added withTransaction(cb) that provides a trx-bound internalAdapter.
    • Utils: added shimLastParam to auto-append the transaction adapter to methods; updated init snapshot to expose withTransaction.

🔄 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/4560 **Author:** [@jslno](https://github.com/jslno) **Created:** 9/10/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `chore/admin-transactions` --- ### 📝 Commits (7) - [`20a0d18`](https://github.com/better-auth/better-auth/commit/20a0d1873b7802a339bbd9eea2e0d497b594bd7a) feat(internal-adapter): add withTransaction helper - [`2a4370b`](https://github.com/better-auth/better-auth/commit/2a4370b9349bdadbcff47e05af60ddf5813e9050) chore: update init snapshot - [`8a70767`](https://github.com/better-auth/better-auth/commit/8a70767506cf0445ec442d0d93f69e87d67a0e2c) chore: cleanup - [`b58a506`](https://github.com/better-auth/better-auth/commit/b58a506af9ffe5c3d687120f57d7c01aee4dbc45) fix: shim appended to wrong parameter - [`1e03d48`](https://github.com/better-auth/better-auth/commit/1e03d48592744f0f5aaed2ab7430da672099b1d0) fix: preserve generics - [`d290e16`](https://github.com/better-auth/better-auth/commit/d290e1613165e83e61296af7f60d0fc614a3b86a) chore: remove unused import - [`f78bbf0`](https://github.com/better-auth/better-auth/commit/f78bbf0fbc41e027d6cbf518d3e685b820ee3f45) chore(admin): use transactions ### 📊 Changes **4 files changed** (+171 additions, -82 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/__snapshots__/init.test.ts.snap` (+1 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+60 -39) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+56 -43) 📝 `packages/better-auth/src/utils/shim.ts` (+54 -0) </details> ### 📄 Description Related: #4554 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Refactored admin flows to run inside database transactions for atomic user creation and bans. Adds internalAdapter.withTransaction and a shim to inject the transaction adapter, improving consistency and preventing partial writes. - **Refactors** - Admin: user creation + credential link now run in a single transaction; banning a user + session revocation also transactionally. - Internal adapter: added withTransaction(cb) that provides a trx-bound internalAdapter. - Utils: added shimLastParam to auto-append the transaction adapter to methods; updated init snapshot to expose withTransaction. <!-- 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-17 21:59:43 -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#31048