-
Notifications
You must be signed in to change notification settings - Fork 290
Description
Describe the problem you'd like to have solved
I'd like to be able to easily integrate Auth0 into a client defined statically in my app (such as ApolloClient) without sacrificing the convenience and features of auth0-react.
Describe the ideal solution
The Auth0Provider component would accept a single client prop, as an alternative to the current props which act as configuration options to be passed to an internally created client instance. This client would be an Auth0Client instance created with auth0-spa-js.
I could then create my own Auth0Client, plug it into my ApolloClient instance using a link, and then provide it to the rest of my app, and I still get the nice convenience of cached authentication state and user data from auth0-react.
Alternatives and current work-arounds
- Re-implement features of
auth0-reactin my own custom React context, like the caching behavior for important information. - Expose or otherwise "steal" the client which
auth0-reactcreates using some terrible magic.
Additional context
For an analogous example of how this is done, see Okta's React library.
This is, in my opinion, the most robust and seamless way to provide higher levels of user customization to a library like this one without complicating the usage for beginners or exposing some kind of static access pattern through a ref or similar confusing method.
Ideally you could just take the client prop and toss it straight into your useState which already exists in the Auth0Provider if it's provided instead of creating your own.