Hi,
We have a use case using React where we need to inject two places with the same Account component like below:
index.tsx
if (document.getElementById('injection-placeholder-1')) {
ReactDOM.render(
<React.StrictMode>
<CommonProviders>
<Account />
</CommonProviders>
</React.StrictMode>,
document.getElementById('injection-placeholder-1')
)
}
if (document.getElementById('injection-placeholder-2')) {
ReactDOM.render(
<React.StrictMode>
<CommonProviders>
<Account />
</CommonProviders>
</React.StrictMode>,
document.getElementById('injection-placeholder-2')
)
}
CommonProviders component
const CommonProviders: React.FC<CommonProvidersProps> = ({ children }) => (
<Auth0Provider
domain={process.env.REACT_APP_AUTH0_DOMAIN ?? ''}
clientId={process.env.REACT_APP_AUTH0_CLIENT_ID ?? ''}
audience={process.env.REACT_APP_AUTH0_AUDIENCE ?? ''}
redirectUri={window.location.origin}
>
{children}
</Auth0Provider>
)
Account component
const Account: React.FC<AccountProps> = () => {
const { isAuthenticated } = useAuth0()
return isAuthenticated ? <a>Log out</a> : <a>Sign in</a>
}
Given that I have used another code to somehow set the Auth0 session in the localhost, the expected output in the browser should be:
Log out
Log out
However, I got below
Log out
Sign in
Does it mean there can be only one Auth0Provider used per React application? How to work around this issue given this use case?
Thanks in advance,
- Which SDK this is regarding: @auth0/auth0-react
- SDK Version: 1.6.0
- Platform Version: Node v14.16.0