# Redirect after login page

**URL:** <https://community.auth0.com/t/redirect-after-login-page/63011>\
**Category:** Get Help\
**Tags:** login, auth0\
**Created:** [May 18, 2021, 5:22pm UTC](https://community.auth0.com/t/redirect-after-login-page/63011 "2021-05-18T17:22:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladymyrivanchenko3](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vladymyrivanchenko3/32/29488_2.png) [@vladymyrivanchenko3](https://community.auth0.com/u/vladymyrivanchenko3)\
**Post date:** [May 18, 2021, 5:22pm UTC](https://community.auth0.com/t/redirect-after-login-page/63011/1 "2021-05-18T17:22:52Z")

</div>

Hello!

I have a NextJS app (shoes store) with many pages and my problem with redirect after login.  
User can click login button at any page (home, some category, product etc., more then 100 pages) and I can’t add all of those pages to the allowed callback URI’s.

How I can implement loginWithRedirect function to redirect user back to any page after login with auth0 without adding all pages to the allowed callback URIs?

loginWithRedirect({ redirectUri: window.location.href })

Probably I can create some rule for allowed callback URIs with \* ? [www.myweb.com/\*](http://www.myweb.com/*) doesn’t work for me…

Settings:  
auth0-react v1.3.0  
next 9.0.2  
react v17.0.1  
Node 10.14.0

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 18, 2021, 6:18pm UTC](https://community.auth0.com/t/redirect-after-login-page/63011/3 "2021-05-18T18:18:24Z")

</div>

Hi @vladymyrivanchenko3,

To set up the redirect URL in a dynamic way, you can use `appState` along with an `onRedirectCallback` in the `Auth0Provider` component:

```auto
const onRedirectCallback = (appState) => {
  history.replace(
    appState && appState.returnTo
      ? appState.returnTo
      : window.location.href
  );
};

ReactDOM.render(
  <Auth0Provider
    domain={config.domain}
    clientId={config.clientId}
    redirectUri={window.location.origin}
    audience={config.audience}
    scope="read:current_user update:current_user_metadata"
    onRedirectCallback={onRedirectCallback}
  >
    <App />
  </Auth0Provider>,
  document.getElementById("root")
);

```

On the login button, you could store the current location path in appState:

```auto
                <NavItem>
                  <Button
                    id="qsLoginBtn"
                    color="primary"
                    className="btn-margin"
                    onClick={() => loginWithRedirect({
                      appState: {
                        returnTo: window.location.pathname
                      }
                    })}
                  >
                    Log In
                  </Button>
                </NavItem>

```

---

<div class="post-metadata">

**Author:** ![vladymyrivanchenko3](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vladymyrivanchenko3/32/29488_2.png) [@vladymyrivanchenko3](https://community.auth0.com/u/vladymyrivanchenko3)\
**Post date:** [May 19, 2021, 10:24am UTC](https://community.auth0.com/t/redirect-after-login-page/63011/4 "2021-05-19T10:24:29Z")

</div>

Thanks @stephanie.chamblee!  
But looks like my onRedirectCallback method doesn’t invoke after login at all.  
Should I add it to the allowedCallback URIs or do something else ?  
I wrapped my \_app.js file with Auth0Provider, it works fine for login from home page without onRedirectCallback func, but probably for NextJs I should wrapped \_document.js file to invoke onRedirectCalback func successfuly ?

---

<div class="post-metadata">

**Author:** ![vladymyrivanchenko3](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vladymyrivanchenko3/32/29488_2.png) [@vladymyrivanchenko3](https://community.auth0.com/u/vladymyrivanchenko3)\
**Post date:** [May 19, 2021, 12:32pm UTC](https://community.auth0.com/t/redirect-after-login-page/63011/5 "2021-05-19T12:32:24Z")

</div>

Solved!  
I’ve added a redirectUri param to the loginWithRedirect function with home page and it helped.

loginWithRedirect({ redirectUri: `${window.location.origin}/home`, appState: {returnTo: href } });

Have a good day!

---

<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:** [June 3, 2021, 12:32pm UTC](https://community.auth0.com/t/redirect-after-login-page/63011/6 "2021-06-03T12:32:58Z")

</div>

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