feat: add client prop to Auth0Provider#1041
Conversation
|
Thanks! 🚀 |
463a4ce to
67b5b75
Compare
|
Awesome 💯 Thank you! |
2b1e9d8 to
5f736f0
Compare
| <MyApp /> | ||
| </Auth0Provider> | ||
| ); | ||
| } |
There was a problem hiding this comment.
We should highlight potential pitfalls and anti patterns with this approach.
What happens if a user initilaise Auth0Provider with both raw client and together
export const auth0Client = createAuth0Client({
domain: 'YOUR_AUTH0_DOMAIN',
clientId: 'YOUR_AUTH0_CLIENT_ID',
authorizationParams: {
redirect_uri: window.location.origin,
},
}); <Auth0Provider
client={auth0Client}
domain={config.domain}
clientId={config.clientId}
key={JSON.stringify(config)}
authorizationParams={{
redirect_uri: window.location.origin,
audience: config.audience || 'default'
}}
...
>
</Auth0Provider>I believe, currently this is allowed, should we add checks to restrict this behaviour or at-least document this as an anti pattern.
There was a problem hiding this comment.
Good catch. Added a runtime console.warn for this case. TypeScript users are already covered at compile time via client?: never on Auth0ProviderWithConfigOptions.
| redirect_uri: window.location.origin, | ||
| }, | ||
| }); | ||
| ``` |
There was a problem hiding this comment.
This may also lead to inconsistent api behaviour, for example
Someone who creates a rawClient would need to call
export const auth0Client = createAuth0Client({
domain: 'YOUR_AUTH0_DOMAIN',
clientId: 'YOUR_AUTH0_CLIENT_ID',
authorizationParams: {
redirect_uri: window.location.origin,
},
});
//called on button click
client.getTokenSilently({ ... })vs
Call silent token token via auth0 hook
var auth0 = useAuth0();
//called on button click
auth0.getAccessTokenSilently({ cacheMode: 'off' })Should we highlight this potential mismatch.
Additionally for anyone using the raw auth0 client via createAuth0Client(...) will internal state in react sdk created in https://github.com/auth0/auth0-react/blob/main/src/reducer.tsx will be updated ?
In case they are not, will there be potential side effects ?
There was a problem hiding this comment.
Added a note on both points: the method naming difference (getTokenSilently vs getAccessTokenSilently), the state sync behaviour, and a callout to avoid calling client.logout() directly on the raw client.
672c6fa to
82cc763
Compare
54dab9c to
4889dce
Compare
What
Adds a
clientprop toAuth0Providerso a pre-configuredAuth0Clientinstance can be shared between the React tree and code outside of React's lifecycle (e.g. TanStack Start client function middleware).Closes #1037. Supersedes #849 (thanks to @rodrigowbazevedo for the original draft).
Usage
Notes
clientprop is unchanged