# ReactJS error with Auth0 protectedroute

**URL:** <https://community.auth0.com/t/reactjs-error-with-auth0-protectedroute/51406>\
**Category:** Get Help\
**Tags:** routes, login, auth0\
**Created:** [October 12, 2020, 11:19am UTC](https://community.auth0.com/t/reactjs-error-with-auth0-protectedroute/51406 "2020-10-12T11:19:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rutiglianomassimilia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rutiglianomassimilia/32/13109_2.png) [@rutiglianomassimilia](https://community.auth0.com/u/rutiglianomassimilia)\
**Post date:** [October 12, 2020, 11:19am UTC](https://community.auth0.com/t/reactjs-error-with-auth0-protectedroute/51406/1 "2020-10-12T11:19:17Z")

</div>

I followed Auth0’s guide to protect routes but once logged while being redirected to my dashboard I get this error:

 ![Auth0error](https://global.discourse-cdn.com/auth0/original/3X/2/f/2f18030d47cc2110ea534cc718094cccc3a5e1a6.png)

This is my codesandbox link with involved files: [App](https://codesandbox.io/s/vigilant-bardeen-fho7n)

This is App.js:

```
import React from "react";
import { useAuth0 } from "@auth0/auth0-react";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import Auth from 'layouts/Auth.js'
import "assets/plugins/nucleo/css/nucleo.css";
import "@fortawesome/fontawesome-free/css/all.min.css";
import "assets/scss/argon-dashboard-react.scss";
import ProtectedRoute from "auth/protected-route.js";
import AdminLayout from "layouts/Admin.js";
import { Loading } from "auth/loading.js";

const App = () => {
  const { isLoading } = useAuth0();

  if (isLoading) {
    return <Loading />;
  }

  return (
    <BrowserRouter h>
      <Switch>

        <ProtectedRoute path="/admin" render={props => <AdminLayout {...props} />} />
        <Route exact path={["/","/prometheusfinancedapp"]} component={Auth} />

      </Switch>
    </BrowserRouter>
  )
};

export default App;

```

My protected route:

```
import React from "react";
import { Route } from "react-router-dom";
import { withAuthenticationRequired } from "@auth0/auth0-react";
import Auth from "../layouts/Auth.js";

const ProtectedRoute = ({ component, ...args }) => (
  <Route
    component={withAuthenticationRequired(component, {
      onRedirecting: () => <Auth />,
    })}
    {...args}
  />
);

export default ProtectedRoute;

```

I have tried various ways to resolve the error but failed. I hope you can help me.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 13, 2020, 9:42pm UTC](https://community.auth0.com/t/reactjs-error-with-auth0-protectedroute/51406/3 "2020-10-13T21:42:50Z")

</div>

Hi @rutiglianomassimilia,

Welcome to the Community!

I tried to look at the code sandbox but am getting a 404 not found.

Can you fix that and post a new link?

---

<div class="post-metadata">

**Author:** ![rutiglianomassimilia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rutiglianomassimilia/32/13109_2.png) [@rutiglianomassimilia](https://community.auth0.com/u/rutiglianomassimilia)\
**Post date:** [October 14, 2020, 7:22am UTC](https://community.auth0.com/t/reactjs-error-with-auth0-protectedroute/51406/4 "2020-10-14T07:22:44Z")

</div>

Sorry, you’re right I don’t know what happened. So I temporarily solved using a Higher-Order component to protect a route but I would like to create a component to protect React Router paths.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 14, 2020, 7:38pm UTC](https://community.auth0.com/t/reactjs-error-with-auth0-protectedroute/51406/5 "2020-10-14T19:38:56Z")

</div>

Sounds good! I am going to mark this resolved 🙂

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 29, 2020, 7:38pm UTC](https://community.auth0.com/t/reactjs-error-with-auth0-protectedroute/51406/6 "2020-10-29T19:38:57Z")

</div>

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