Skip to content

feat: add support for pre-configured Auth0Client instance in Auth0Pro… #849

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

rodrigowbazevedo
Copy link

@rodrigowbazevedo rodrigowbazevedo commented Jun 25, 2025

Add support for pre-configured Auth0Client instance in Auth0Provider

Description

This PR introduces a new optional client prop to the Auth0Provider component, allowing developers to pass a pre-configured Auth0Client instance instead of having the provider create one internally.

Changes

  • Added client prop to Auth0ProviderOptions interface with comprehensive JSDoc documentation
  • Updated Auth0Provider component to use the provided client instance when available, falling back to creating a new one if not provided
  • Added test coverage to verify that when a client instance is provided, no new Auth0Client is instantiated

Use Cases

This enhancement enables several important scenarios:

  • Shared client instances: Use a single Auth0Client inside and outside a React app scope
  • Custom configuration: Pass clients with advanced or specialized configuration
  • Testing: Inject mock clients for unit and integration tests
  • Fine-grained control: Manage client initialization timing externally
Example Usage
const domain = 'your-domain.auth0.com';
const clientId = 'your-client-id';
const customClient = new Auth0Client({
  domain,
  clientId,
  // ... other options
});

<Auth0Provider client={customClient} domain={domain} clientId={clientId}>
  <App />
</Auth0Provider>

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 client prop is provided, no new Auth0Client instance is created

  • Existing tests continue to pass, ensuring no regression in current functionality

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not the default branch

@rodrigowbazevedo rodrigowbazevedo marked this pull request as ready for review June 25, 2025 13:43
@rodrigowbazevedo rodrigowbazevedo requested a review from a team as a code owner June 25, 2025 13:43
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.

1 participant