Checklist
Describe the problem you'd like to have solved
Accessing Auth0Client and it's methods like getAccessTokenSilently outside of React has historically been a point of frustration for myself and other developers.
Describe the ideal solution
Expose Auth0Client and allow for it to be passed to an Auth0Provider. This pattern is used by popular framework-agnostic libraries like TanStack Query.
import { Auth0Client, Auth0Provider } from '@auth0/auth0-react'
const client = new Auth0Client({ /* ... */ })
function App () {
return <Auth0Provider client={client}>{ /* ... */ }</Auth0Provider>
}
Alternatives and current workarounds
One workaround is to useAuth0 and extract methods to an external store. However, this approach is not viable when Auth0Client is needed before React renders.
const { getAccessTokenSilently } = useAuth0()
useLayoutEffect(() => {
window.getAccessTokenSilently = getAccessTokenSilently
}, [getAccessTokenSilently])
Another is to use auth0-spa-js instead of/in addition to auth0-react. Not using the React library leads to developers reimplementing the library, while using them together can lead to increased bundle size or incompatibility if the versions are mismatched.
Additional context
No response
Checklist
Describe the problem you'd like to have solved
Accessing
Auth0Clientand it's methods likegetAccessTokenSilentlyoutside of React has historically been a point of frustration for myself and other developers.Describe the ideal solution
Expose
Auth0Clientand allow for it to be passed to anAuth0Provider. This pattern is used by popular framework-agnostic libraries like TanStack Query.Alternatives and current workarounds
One workaround is to
useAuth0and extract methods to an external store. However, this approach is not viable whenAuth0Clientis needed before React renders.Another is to use auth0-spa-js instead of/in addition to auth0-react. Not using the React library leads to developers reimplementing the library, while using them together can lead to increased bundle size or incompatibility if the versions are mismatched.
Additional context
No response