# Using open and closed parts of React site with the same API

**URL:** <https://community.auth0.com/t/using-open-and-closed-parts-of-react-site-with-the-same-api/66810>\
**Category:** Get Help\
**Created:** [July 26, 2021, 12:51pm UTC](https://community.auth0.com/t/using-open-and-closed-parts-of-react-site-with-the-same-api/66810 "2021-07-26T12:51:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![oystein](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oystein/32/27617_2.png) [@oystein](https://community.auth0.com/u/oystein)\
**Post date:** [July 26, 2021, 12:51pm UTC](https://community.auth0.com/t/using-open-and-closed-parts-of-react-site-with-the-same-api/66810/1 "2021-07-26T12:51:48Z")

</div>

Hello. I’m creating a React web app for a business whose customers can generate quotes without logging in (ie. no login required). And now I’m adding an internal dashboard with Auth0 login, where the employees can manage quotes, see statistics etc. I’ve got a Node backend with an API called from the frontend. The API has so far only had endpoints available openly, but I now want to add specific endpoints that should be limited by an Auth0 login.

How can I have both open and closed endpoints in the same API, called from a React frontend?

---

<div class="post-metadata">

**Author:** ![oystein](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oystein/32/27617_2.png) [@oystein](https://community.auth0.com/u/oystein)\
**Post date:** [July 28, 2021, 8:55am UTC](https://community.auth0.com/t/using-open-and-closed-parts-of-react-site-with-the-same-api/66810/2 "2021-07-28T08:55:46Z")

</div>

I figured it out after following a more extended tutorial on setting up Auth0 in a React environment: [React and Auth0 Crash Course and Workshop - YouTube](https://youtu.be/PYWS-4CXETw)

EDIT: Just to add some more information, the solution was the JWT middleware used in the backend. By adding a helper function using the `express-jwt` and `jwks-rsa` packages, that helper function could be added to the endpoints you want protected. The endpoints without the helper function still works fine without any authorization.

```auto
messagesRouter.get("/public-message", (req, res) => {
  const message = getPublicMessage();
  res.status(200).send(message);
});

messagesRouter.get("/protected-message", checkJwt, (req, res) => {
  const message = getProtectedMessage();
  res.status(200).send(message);
});

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 28, 2021, 10:31am UTC](https://community.auth0.com/t/using-open-and-closed-parts-of-react-site-with-the-same-api/66810/3 "2021-07-28T10:31:01Z")

</div>

Perfect! Thanks for sharing that with the rest of community!

---

<div class="post-metadata">

**Author:** ![oystein](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oystein/32/27617_2.png) [@oystein](https://community.auth0.com/u/oystein)\
**Post date:** [July 28, 2021, 10:51am UTC](https://community.auth0.com/t/using-open-and-closed-parts-of-react-site-with-the-same-api/66810/4 "2021-07-28T10:51:23Z")

</div>

No problem. Just glad I found it out. 🙂

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 29, 2021, 10:59am UTC](https://community.auth0.com/t/using-open-and-closed-parts-of-react-site-with-the-same-api/66810/5 "2021-07-29T10:59:48Z")

</div>


