Skip to content

Accept client as a prop in Auth0Provider #1037

@roccomaniscalco

Description

@roccomaniscalco

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions