# App infinitely redirecting after login ReactJS {PLEASE HELP}

**URL:** <https://community.auth0.com/t/app-infinitely-redirecting-after-login-reactjs-please-help/87782>\
**Category:** Get Help\
**Tags:** login, auth0\
**Created:** [July 28, 2022, 3:12am UTC](https://community.auth0.com/t/app-infinitely-redirecting-after-login-reactjs-please-help/87782 "2022-07-28T03:12:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![agentggg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/agentggg/32/39020_2.png) [@agentggg](https://community.auth0.com/u/agentggg)\
**Post date:** [July 28, 2022, 3:12am UTC](https://community.auth0.com/t/app-infinitely-redirecting-after-login-reactjs-please-help/87782/1 "2022-07-28T03:12:20Z")

</div>

Hey there, my ReactJS App is infinitely looping after login. Loops between my homepage and then the Auth0 login page. I have this error in incognito, and regular. Also have error with all browser.

Below is code snippets. Any thoughts?

import { Auth0Provider } from ‘@auth0/auth0-react’;

**App.js**

```auto
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <Auth0Provider
    domain="dev-1v7prir5.us.auth0.com"
    clientId="8dlquRgNeFZqx9TgkaYPR7U3tTKCENaS"
    redirectUri={window.location.origin}
    cacheLocation="localstorage"
    useRefreshTokens={true}
  >
    <App />
  </Auth0Provider>

```

**Homepage**

`export default withAuthenticationRequired(Homepage)`

**My login page that redirects user**

```auto
const LoginIdentity = () => { 
    const { loginWithRedirect, isLoading, error} = useAuth0();
    // used for navigation
    useEffect(() => {
        loginWithRedirect()
      },[]);
      if (isLoading) {
        return <div>Loading...</div>;
      }
      if (error) {
        return <div>Oops... {error.message}</div>;
      }
    }
export default LoginIdentity

```

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [July 29, 2022, 8:23pm UTC](https://community.auth0.com/t/app-infinitely-redirecting-after-login-reactjs-please-help/87782/2 "2022-07-29T20:23:57Z")

</div>

@agentggg

When you use `loginWithRedirect()`, you are redirecting the user to the Universal Login page.  
However, if the user has already logged in and has a valid Auth0 session already, then `loginWithRedirect()` will bring the user to the Universal Login page, detect their valid login automatically, and redirect them to the `redirectUri` defined in the request.

Without looking at how you’ve set up the code, you might always be calling the `loginWithRedirect()` function on the page without checking if the user is already logged in first.

Take a look at the Getting Started section of the auth0-react SDK here: [@auth0/auth0-react](https://auth0.github.io/auth0-react/#getting-started) (specifically where it uses `isAuthenticated` to determine whether to show a login button or a logout button)

Hope that helps!

---

<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:** [August 1, 2022, 9:55am UTC](https://community.auth0.com/t/app-infinitely-redirecting-after-login-reactjs-please-help/87782/3 "2022-08-01T09:55:15Z")

</div>

Thanks for sharing that with the rest of community!

---

<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:** [November 4, 2022, 1:25pm UTC](https://community.auth0.com/t/app-infinitely-redirecting-after-login-reactjs-please-help/87782/4 "2022-11-04T13:25:53Z")

</div>


