[PR #3936] [CLOSED] fix: prevent createAuthClient from being treated as thenable #5096

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3936
Author: @Louis454545
Created: 8/11/2025
Status: Closed

Base: canaryHead: fix/issue-3657-vitest-fixture-hang


📝 Commits (1)

  • 870b9b5 fix: prevent createAuthClient from being treated as thenable

📊 Changes

3 files changed (+376 additions, -0 deletions)

View changed files

.claude/commands/issue_resolver.md (+350 -0)
📝 packages/better-auth/src/client/client.test.ts (+22 -0)
📝 packages/better-auth/src/client/proxy.ts (+4 -0)

📄 Description

Summary

Fixes #3657

This PR resolves a bug where createAuthClient() returns a Proxy that gets treated as a thenable by Promise.resolve(), causing Vitest fixtures to hang indefinitely.

Changes Made

  • Fix Proxy handler: Added guard in packages/better-auth/src/client/proxy.ts to return undefined for 'then' property access
  • Regression test: Added test in packages/better-auth/src/client/client.test.ts to verify the fix and prevent future regressions

Root Cause

The Proxy's get handler always returned a value for any property access, including 'then'. This caused:

  1. Promise.resolve(createAuthClient()) to treat the client as a thenable
  2. Vitest fixtures using the client to create a never-resolving Promise
  3. Test hangs requiring force termination

Testing

  • Added comprehensive test coverage for thenable behavior
  • Verified existing client functionality remains intact
  • Confirmed fix resolves the specific Vitest fixture use case

Impact

  • Fixes testing ergonomics for all Vitest users
  • No breaking changes to existing API
  • Small, focused change with minimal risk
  • Prevents similar issues with other Promise-based tools

🤖 Generated with Claude Code


Summary by cubic

Fixed a bug where createAuthClient was incorrectly treated as a thenable, causing Vitest fixtures to hang.

  • Bug Fixes
  • Added a guard to the proxy handler so accessing the 'then' property returns undefined.
  • Added a regression test to confirm Promise.resolve does not treat the client as a thenable.

🔄 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/3936 **Author:** [@Louis454545](https://github.com/Louis454545) **Created:** 8/11/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/issue-3657-vitest-fixture-hang` --- ### 📝 Commits (1) - [`870b9b5`](https://github.com/better-auth/better-auth/commit/870b9b56211bb52945bf65cf69e00430e543f011) fix: prevent createAuthClient from being treated as thenable ### 📊 Changes **3 files changed** (+376 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `.claude/commands/issue_resolver.md` (+350 -0) 📝 `packages/better-auth/src/client/client.test.ts` (+22 -0) 📝 `packages/better-auth/src/client/proxy.ts` (+4 -0) </details> ### 📄 Description ## Summary Fixes #3657 This PR resolves a bug where `createAuthClient()` returns a Proxy that gets treated as a thenable by Promise.resolve(), causing Vitest fixtures to hang indefinitely. ## Changes Made - **Fix Proxy handler**: Added guard in `packages/better-auth/src/client/proxy.ts` to return `undefined` for `'then'` property access - **Regression test**: Added test in `packages/better-auth/src/client/client.test.ts` to verify the fix and prevent future regressions ## Root Cause The Proxy's `get` handler always returned a value for any property access, including `'then'`. This caused: 1. Promise.resolve(createAuthClient()) to treat the client as a thenable 2. Vitest fixtures using the client to create a never-resolving Promise 3. Test hangs requiring force termination ## Testing - [x] Added comprehensive test coverage for thenable behavior - [x] Verified existing client functionality remains intact - [x] Confirmed fix resolves the specific Vitest fixture use case ## Impact - ✅ Fixes testing ergonomics for all Vitest users - ✅ No breaking changes to existing API - ✅ Small, focused change with minimal risk - ✅ Prevents similar issues with other Promise-based tools 🤖 Generated with [Claude Code](https://claude.ai/code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed a bug where createAuthClient was incorrectly treated as a thenable, causing Vitest fixtures to hang. - **Bug Fixes** - Added a guard to the proxy handler so accessing the 'then' property returns undefined. - Added a regression test to confirm Promise.resolve does not treat the client as a thenable. <!-- 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:10:37 -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#5096