[PR #5043] [CLOSED] fix: handle adapters without transaction support in createOAuthUser #5734

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5043
Author: @himself65
Created: 10/2/2025
Status: Closed

Base: v1.3.x-latestHead: v1.3.x-latest


📝 Commits (5)

  • 7d1f211 chore: fix social provider tests
  • af3a79e refactor: move user input parser to api endpoints
  • 9b7e5a0 chore: remove log
  • 73e1e2e chore: release v1.3.25
  • dd8d600 fix: handle adapters without transaction support in createOAuthUser

📊 Changes

13 files changed (+112 additions, -23 deletions)

View changed files

📝 package.json (+1 -1)
📝 packages/better-auth/package.json (+1 -1)
📝 packages/better-auth/src/adapters/adapter-factory/index.ts (+1 -0)
📝 packages/better-auth/src/api/routes/sign-up.test.ts (+57 -0)
📝 packages/better-auth/src/api/routes/sign-up.ts (+28 -12)
📝 packages/better-auth/src/db/internal-adapter.ts (+9 -2)
📝 packages/better-auth/src/db/schema.ts (+9 -1)
📝 packages/better-auth/tsconfig.json (+1 -1)
📝 packages/cli/package.json (+1 -1)
📝 packages/core/package.json (+1 -1)
📝 packages/expo/package.json (+1 -1)
📝 packages/sso/package.json (+1 -1)
📝 packages/stripe/package.json (+1 -1)

📄 Description

Summary

Fixes #5035 - App crashes when custom adapter doesn't implement transaction method

Changes

  • Added check in createOAuthUser to verify if adapter.transaction exists before calling it
  • Falls back to sequential execution (no-op transaction) for adapters without transaction support
  • Fixed merge conflict markers in adapter-factory/index.ts

Problem

When users create custom adapters without implementing the transaction method, the app crashes with:

TypeError: adapter.transaction is not a function

This occurs even when transaction: false is set in the adapter config.

Solution

The fix follows the same pattern used in adapter-factory/index.ts:

  • If the adapter has a transaction method, use it
  • Otherwise, execute operations sequentially by passing the adapter itself as the transaction adapter

This provides a graceful fallback for adapters that don't support transactions, maintaining atomicity guarantees where possible while allowing sequential execution when necessary.

Test plan

  • Build passes
  • Existing tests pass (createOAuthUser test already exists)
  • Fix follows existing patterns in the codebase

🤖 Generated with Claude Code


Summary by cubic

Fixes #5035: Prevent crash in createOAuthUser when adapters don't implement transaction. Falls back to sequential execution when transaction is missing, keeps the transactional path when available, and cleans up merge conflict markers.


🔄 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/5043 **Author:** [@himself65](https://github.com/himself65) **Created:** 10/2/2025 **Status:** ❌ Closed **Base:** `v1.3.x-latest` ← **Head:** `v1.3.x-latest` --- ### 📝 Commits (5) - [`7d1f211`](https://github.com/better-auth/better-auth/commit/7d1f211e4ffccb3e90c2242320b0c44cd4292315) chore: fix social provider tests - [`af3a79e`](https://github.com/better-auth/better-auth/commit/af3a79e066d505066172eaaca94dfff2507efb13) refactor: move user input parser to api endpoints - [`9b7e5a0`](https://github.com/better-auth/better-auth/commit/9b7e5a0d7be901583a03ebafe3a2da1bd1ddade2) chore: remove log - [`73e1e2e`](https://github.com/better-auth/better-auth/commit/73e1e2eaa28fe46fe8a863a3e65f9ce9bd200d53) chore: release v1.3.25 - [`dd8d600`](https://github.com/better-auth/better-auth/commit/dd8d600115ab153a79f2d05dc6f2e5e1928e61ce) fix: handle adapters without transaction support in createOAuthUser ### 📊 Changes **13 files changed** (+112 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `package.json` (+1 -1) 📝 `packages/better-auth/package.json` (+1 -1) 📝 `packages/better-auth/src/adapters/adapter-factory/index.ts` (+1 -0) 📝 `packages/better-auth/src/api/routes/sign-up.test.ts` (+57 -0) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+28 -12) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+9 -2) 📝 `packages/better-auth/src/db/schema.ts` (+9 -1) 📝 `packages/better-auth/tsconfig.json` (+1 -1) 📝 `packages/cli/package.json` (+1 -1) 📝 `packages/core/package.json` (+1 -1) 📝 `packages/expo/package.json` (+1 -1) 📝 `packages/sso/package.json` (+1 -1) 📝 `packages/stripe/package.json` (+1 -1) </details> ### 📄 Description ## Summary Fixes #5035 - App crashes when custom adapter doesn't implement transaction method ## Changes - Added check in `createOAuthUser` to verify if `adapter.transaction` exists before calling it - Falls back to sequential execution (no-op transaction) for adapters without transaction support - Fixed merge conflict markers in `adapter-factory/index.ts` ## Problem When users create custom adapters without implementing the `transaction` method, the app crashes with: ``` TypeError: adapter.transaction is not a function ``` This occurs even when `transaction: false` is set in the adapter config. ## Solution The fix follows the same pattern used in `adapter-factory/index.ts`: - If the adapter has a `transaction` method, use it - Otherwise, execute operations sequentially by passing the adapter itself as the transaction adapter This provides a graceful fallback for adapters that don't support transactions, maintaining atomicity guarantees where possible while allowing sequential execution when necessary. ## Test plan - [x] Build passes - [x] Existing tests pass (createOAuthUser test already exists) - [x] Fix follows existing patterns in the codebase 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes #5035: Prevent crash in createOAuthUser when adapters don't implement transaction. Falls back to sequential execution when transaction is missing, keeps the transactional path when available, and cleans up merge conflict markers. <!-- 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:33: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#5734