auth0/auth0-react

Support using existing Auth0Client to improve performance

sijakret opened this issue · 2 comments

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

Currently, in our react application, authentication is only kicked of after the first react render call (i.e. when the context is instantiated).

To improve bootstrapping of our react app we want to start authentication BEFORE react even starts rendering (or is even loaded). This idea has been uttered before (#278 (comment)) and there exists a document with reasoning against it here: https://gist.github.com/adamjmcgrath/0ed6a04047aad16506ca24d85f1b2a5c
In our case we are also NOT interested in having multiple clients but are interested in the ability to immediately start checking the session right after the auth0client code is available and not only when the first react render call is happening?

Is this possible?

  • If so: how? :)
  • If not: Are there plans to enable it?

Thanky you for any input!

Describe the ideal solution

Possible solutions:

  1. provide an imperative API to either provide an existing Auth0Client to the context provider
  2. provide a way to configure + trigger authentication before react context+context provider are even created.

Alternatives and current workarounds

No response

Additional context

No response

Thanks for reaching out. As you mention yourself, this has been asked for before and we still have no plans to support this.

I do want to call out the fact that our Auth0-React SDK is a tiny wrapper around Auth0-SPA-JS, that is build around the provider and context API for react.

If this is not what you want (which is the case, as you want to exit the Provider way of instantiating the client), it's perfectly fine to use Auth0-SPA-JS directly. You can have a look at our Auth0-React SDK and rebuild whatever you want around Auth0-SPA-JS yourself to better suit your needs (in essence, Auth0-React is just Auth0-SPA-JS packed in a Provider + Contect API + Hook).

So long story short:

  • It is not possible using Auth0-React, as this is a thin and opiniated Auth0-SPA-JS implementation for React.
  • There are no plans to enable support for this, because it is already possible when using Auth0-SPA-JS directly.

Sure, using Auth0-SPA-JS directly can feel a bit complicated, but we encourage that for everyone that has more complicated use-cases as what our Auth0-React SDK offers out of the box.

got it, thanks for the explanation!