Skip to content

feat: add client prop and createAuth0Client factory#1041

Open
yogeshchoudhary147 wants to merge 5 commits intomainfrom
feat/client-prop-and-factory
Open

feat: add client prop and createAuth0Client factory#1041
yogeshchoudhary147 wants to merge 5 commits intomainfrom
feat/client-prop-and-factory

Conversation

@yogeshchoudhary147
Copy link
Contributor

@yogeshchoudhary147 yogeshchoudhary147 commented Mar 9, 2026

What

Adds two new exports to address the pain point of accessing Auth0 from code that has no access to React's lifecycle (e.g. TanStack Start client function middleware).

  • createAuth0Client(options) — a factory that creates an Auth0Client with the auth0-react telemetry header pre-configured. This is the recommended way to create a client when you need to share it outside of React.
  • client prop on Auth0Provider — accepts a pre-configured Auth0Client instance instead of creating one internally. When client is provided, domain and clientId become optional.

Closes #1037. Supersedes #849 (thanks to @rodrigowbazevedo for the original draft).

Usage

import { createAuth0Client, Auth0Provider } from '@auth0/auth0-react';

// Create once — use anywhere
const client = createAuth0Client({ 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
  • createAuth0Client is preferred over new Auth0Client() directly as it injects the correct SDK telemetry header
  • Auth0Client is also now exported from this package for cases where users manage the client themselves

@yogeshchoudhary147 yogeshchoudhary147 requested a review from a team as a code owner March 9, 2026 11:52
@rodrigowbazevedo
Copy link

Thanks! 🚀

@yogeshchoudhary147 yogeshchoudhary147 force-pushed the feat/client-prop-and-factory branch from 463a4ce to 67b5b75 Compare March 9, 2026 13:22
@roccomaniscalco
Copy link

Awesome 💯 Thank you!

EXAMPLES.md Outdated
import axios from 'axios';
import { auth0Client } from './auth0-client';

axios.interceptors.request.use(async (config) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interceptor example is beautiful 🚀

@yogeshchoudhary147 yogeshchoudhary147 force-pushed the feat/client-prop-and-factory branch from 37bae1e to 2b1e9d8 Compare March 13, 2026 05:55
@yogeshchoudhary147 yogeshchoudhary147 force-pushed the feat/client-prop-and-factory branch from 2b1e9d8 to 5f736f0 Compare March 13, 2026 05:58
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.

Accept client as a prop in Auth0Provider

3 participants