# Use two Auth0Provider (one for each React injection) causing one injection not working

**URL:** <https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901>\
**Category:** Get Help\
**Tags:** react-sdk, auth0\
**Created:** [September 19, 2021, 12:18pm UTC](https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901 "2021-09-19T12:18:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben.liu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ben.liu/32/13314_2.png) [@ben.liu](https://community.auth0.com/u/ben.liu)\
**Post date:** [September 19, 2021, 12:18pm UTC](https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901/1 "2021-09-19T12:18:30Z")

</div>

Hi,

We have a use case using React where we need to inject two places with the same Account component like below:

`index.tsx`

```auto
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

```auto
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

```auto
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:

```auto
Log out
Log out

```

However, I got below

```auto
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

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [September 20, 2021, 11:51pm UTC](https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901/3 "2021-09-20T23:51:42Z")

</div>

Hi @ben.liu,

Welcome to the Auth0 Community.

I understand that you have questions regarding using two Auth0Providers.

> [@ben.liu](#):
>
> Does it mean there can be only one Auth0Provider used per React application? How to work around this issue given this use case?

Generally, there can only be a single `Auth0Provider` component that you can use to wrap your application. This will provide the React Context to components that are placed inside your application.

Having more than one `Auth0Provider` will cause conflicts such as the behavior you see with your implementation.

Regarding a workaround, I recommend checking out this related Community Topic that addresses using two Auth0Providers in a Single React App: [https://community.auth0.com/t/using-2-auth0providers-in-a-single-react-app/52455](https://community.auth0.com/t/using-2-auth0providers-in-a-single-react-app/52455)

Please let me know if this resolves your issue.

Thank you.

---

<div class="post-metadata">

**Author:** ![ben.liu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ben.liu/32/13314_2.png) [@ben.liu](https://community.auth0.com/u/ben.liu)\
**Post date:** [September 21, 2021, 2:28am UTC](https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901/4 "2021-09-21T02:28:56Z")

</div>

Hey @rueben.tiow ,

thanks for your response.

By inspecting into the link of workaround, it looks like a different use case where there are two AuthProviders pointing to DIFFERENT client ids (therefore using `skipRedirectCallback` to avoid conflict), whereas in my use case, both AuthProviders are pointing to the SAME client id.

Any other way to work around this issue?

Best Regards,  
Ben

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [September 23, 2021, 5:20pm UTC](https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901/5 "2021-09-23T17:20:29Z")

</div>

Hi @ben.liu,

Thank you for clarifying.

Unfortunately, you can only use a single `Auth0Provider` in your application when using one application (clientID).

To understand your use case better, could you please elaborate more on why you intend to use two Auth0Providers pointing to the same clientID?

Thank you.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 11, 2021, 6:26pm UTC](https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901/8 "2021-10-11T18:26:03Z")

</div>



---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 11, 2021, 6:28pm UTC](https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901/9 "2021-10-11T18:28:20Z")

</div>

Hi @ben.liu,

I hope you are doing well.

It’s been some time since we have heard from you. If you still have concerns regarding your initial question, please feel free to reply to us here.

Otherwise, this topic will automatically close in a couple of weeks.

Thank you.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 26, 2021, 6:28pm UTC](https://community.auth0.com/t/use-two-auth0provider-one-for-each-react-injection-causing-one-injection-not-working/69901/10 "2021-10-26T18:28:29Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
