Skip to content

Allow the user to pass in a pre-existing Auth0Client #105

@a-type

Description

@a-type

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

  1. Re-implement features of auth0-react in my own custom React context, like the caching behavior for important information.
  2. Expose or otherwise "steal" the client which auth0-react creates 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions