feat: add support for pre-configured Auth0Client instance in Auth0Pro…#849
Closed
rodrigowbazevedo wants to merge 1 commit intoauth0:mainfrom
Closed
feat: add support for pre-configured Auth0Client instance in Auth0Pro…#849rodrigowbazevedo wants to merge 1 commit intoauth0:mainfrom
rodrigowbazevedo wants to merge 1 commit intoauth0:mainfrom
Conversation
5 tasks
Contributor
|
Closing in favor of #1041 which builds on this work to also add a |
yogeshchoudhary147
added a commit
that referenced
this pull request
Mar 20, 2026
## What Adds a `client` prop to `Auth0Provider` so a pre-configured `Auth0Client` instance can be shared between the React tree and code outside of React's lifecycle (e.g. TanStack Start client function middleware). Closes #1037. Supersedes #849 (thanks to @rodrigowbazevedo for the original draft). ## Usage ```tsx import { Auth0Client } from '@auth0/auth0-spa-js'; import { Auth0Provider } from '@auth0/auth0-react'; const client = new Auth0Client({ domain, clientId }); // Outside React (e.g. TanStack Start client function middleware) // Note: the raw Auth0Client method is getTokenSilently (not getAccessTokenSilently) const token = await client.getTokenSilently(); // Inside React — Auth0Provider uses the same client instance function App() { return <Auth0Provider client={client}><MyApp /></Auth0Provider>; } ``` ## Notes - Fully backward compatible — existing usage without `client` prop is unchanged - Calling methods on the raw client does not update React state — use hooks inside React for that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for pre-configured Auth0Client instance in Auth0Provider
Description
This PR introduces a new optional
clientprop to theAuth0Providercomponent, allowing developers to pass a pre-configuredAuth0Clientinstance instead of having the provider create one internally.Changes
clientprop toAuth0ProviderOptionsinterface with comprehensive JSDoc documentationAuth0Providercomponent to use the provided client instance when available, falling back to creating a new one if not providedAuth0Clientis instantiatedUse Cases
This enhancement enables several important scenarios:
Example Usage
Backward Compatibility
This change is fully backward compatible. Existing implementations will continue to work unchanged, as the client prop is optional and the provider maintains its existing behavior when not provided.
Testing
Added unit test to verify that when a
clientprop is provided, no newAuth0Clientinstance is createdExisting tests continue to pass, ensuring no regression in current functionality
This change adds test coverage for new/changed/fixed functionality
Checklist