Skip to content

fix: resolve stale closure bug in fetchToken callback #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iskng
Copy link

@iskng iskng commented Aug 12, 2025

The fetchToken callback in ConvexBetterAuthProvider had incorrect dependencies, causing it to capture stale authClient references. This prevented Convex JWT token fetching from working correctly when authClient prop changed or plugins were dynamically loaded.

  • Updated dependency array from [client] to [authClient, logVerbose]
  • Ensures callback updates when authClient changes (fixing dynamic plugin loading)
  • Fixes silent authentication failures in mobile/native apps using Better Auth with Convex

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The fetchToken callback in ConvexBetterAuthProvider had incorrect dependencies,
causing it to capture stale authClient references. This prevented Convex JWT
token fetching from working correctly when authClient prop changed or plugins
were dynamically loaded.

- Updated dependency array from [client] to [authClient, logVerbose]
- Ensures callback updates when authClient changes (fixing dynamic plugin loading)
- Fixes silent authentication failures in mobile/native apps using Better Auth with Convex

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@erquhart
Copy link
Collaborator

Yeah this is fair, but we also still want to invalidate if the convex client changes. I think this fix only affects dynamic client plugin loading use cases, did you see mobile/native being affected beyond that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants