# How to redirect to a different page based on signup vs login screen?

**URL:** <https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258>\
**Category:** Get Help\
**Tags:** login\
**Created:** [March 29, 2021, 4:32pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258 "2021-03-29T16:32:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor-wei126](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/victor-wei126/32/28140_2.png) [@victor-wei126](https://community.auth0.com/u/victor-wei126)\
**Post date:** [March 29, 2021, 4:32pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/1 "2021-03-29T16:32:33Z")

</div>

Currently, I am using the New universal login experience. With this, I am using the React SDK, which has a function loginWithRedirect. When users click the login button, I simply run this function. When users click the signup button, I run loginWithRedirect({screen\_hint: ‘signup’}), since as said in the docs, passing a parameter set to signup will redirect users to the signup page. However, these two functions do the exact same thing, they both lead to login, and the signup button doesn’t lead to signup. How do I get this to work?

---

<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:** [March 30, 2021, 7:24pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/3 "2021-03-30T19:24:13Z")

</div>

Hi @victor-wei126,

The call to `loginWithRedirect({screen_hint: ‘signup’})` looks correct and should redirect you to the signup page. In order to help recreate this, would you mind sending more of the code you are using with the sing up button?

[https://community.auth0.com/t/how-do-i-redirect-users-directly-to-the-hosted-signup-page/42520](https://community.auth0.com/t/how-do-i-redirect-users-directly-to-the-hosted-signup-page/42520)

---

<div class="post-metadata">

**Author:** ![victor-wei126](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/victor-wei126/32/28140_2.png) [@victor-wei126](https://community.auth0.com/u/victor-wei126)\
**Post date:** [March 31, 2021, 6:00pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/4 "2021-03-31T18:00:02Z")

</div>

Hi Stephanie,

You are correct, it does redirect me to the proper /login or /signup endpoint depending on the button I click. Here is my code:

const LoginButton = () =\> {  
const { loginWithRedirect, isAuthenticated } = useAuth0();

return (  
!isAuthenticated && (  
\<Nav.Link onClick={() =\> loginWithRedirect()}\>  
Log in  
\</Nav.Link\>  
)  
);  
}

const SignUpButton = () =\> {  
const { loginWithRedirect, isAuthenticated } = useAuth0();

return (  
!isAuthenticated && (  
\<Nav.Link onClick={() =\> loginWithRedirect({screen\_hint: ‘signup’})}\>  
Sign Up  
\</Nav.Link\>  
)  
);  
}

The buttons redirect to the proper endpoint, however, my problem is that once the user clicks the “continue” button on the forms of each page, the user is redirected to a different URL in my application. For example, when the user is new, ie, signs up, I would like to redirect them to /signupinfo which is a form that collects additional sign up information. But if it is a returning user, they would go to the login endpoint, and from there be redirected straight to their dashboard. So to recap, 2 different workflows:

1. New users: /home → /signup → /signupinfo → /dashboard
2. Returning users: /home → /login → /dashboard.

I looked into redirecting users within rules, but that seems to be more complicated then I need it to be, since I am just returning control to my application, I don’t need any additional redirects. It seems to me since users will either be on /signup or /login, I can just route the redirect to a different URL based on which “continue” button they click, if that makes sense. Thanks!

---

<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:** [April 1, 2021, 1:26pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/5 "2021-04-01T13:26:56Z")

</div>

You could use appState to redirect the user:

1. Write a `onRedirectCallback` fn for the `Auth0Provider`:

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

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

```

1. set the `returnTo` value in appState when calling `loginWithRedirect` for the “Sign Up” button:

```auto
                  <Button
                    id="qsLoginBtn"
                    color="primary"
                    className="btn-margin"
                    onClick={() => loginWithRedirect({
                      screen_hint: 'signup',
                      appState: {
                        returnTo: '/signupinfo'
                      }
                    })}
                  >
                    Sign up
                  </Button>

```

---

<div class="post-metadata">

**Author:** ![victor-wei126](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/victor-wei126/32/28140_2.png) [@victor-wei126](https://community.auth0.com/u/victor-wei126)\
**Post date:** [April 2, 2021, 6:39pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/6 "2021-04-02T18:39:43Z")

</div>

I appreciate the attempt to help, but unfortunately this completely broke my app, and I am very unsure about what just happened, so I won’t attempt to ask lol.

Could you please explain what this code does and how it works, or refer me to some documentation? I understand the history object, but what are the appState and returnTo?

---

<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:** [April 6, 2021, 11:07am UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/8 "2021-04-06T11:07:20Z")

</div>

Deleted previous message due to SPAM reasons.

---

<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:** [April 6, 2021, 12:12pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/9 "2021-04-06T12:12:54Z")

</div>

Hi @victor-wei126,

I just tested this out without doing step 1, and the redirect still occurs. I was mistaken, that step is not necessary for this.

You can simply update the app state when you call `loginWithRedirect`:

```auto
                  <Button
                    id="qsLoginBtn"
                    color="primary"
                    className="btn-margin"
                    onClick={() => loginWithRedirect({
                      screen_hint: 'signup',
                      appState: {
                        returnTo: '/signupinfo'
                      }
                    })}
                  >
                    Sign up
                  </Button>

```

The appState is used to store the application’s state before the user is redirected: [https://auth0.github.io/auth0-react/modules/auth0\_provider.html#appstate](https://auth0.github.io/auth0-react/modules/auth0_provider.html#appstate)

The `onRedirectCallback` method can be used if you are using a custom router such as `react-router-dom`: [https://auth0.github.io/auth0-react/interfaces/auth0\_provider.auth0provideroptions.html#onredirectcallback](https://auth0.github.io/auth0-react/interfaces/auth0_provider.auth0provideroptions.html#onredirectcallback)

---

<div class="post-metadata">

**Author:** ![victor-wei126](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/victor-wei126/32/28140_2.png) [@victor-wei126](https://community.auth0.com/u/victor-wei126)\
**Post date:** [April 6, 2021, 7:02pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/10 "2021-04-06T19:02:23Z")

</div>

Hi Stephanie,

I tried this out and it has solved the problem somewhat. What happens now is that after the user clicks “sign up” on the sign up form, they are first redirected to /dashboard. Then, when I manually refresh the page, it then redirects to /signupinfo. I think this is because in Auth0Provider, I have the redirectUri=“/dashboard”, so it redirects to there. I tried removing this property, and then adding the appState option to the loginWithRedirect for the login up button, but with the returnTo set to ‘/dashboard’, but this caused some weird service outtage issues so I’m guessing the redirectUri is required?

Is there any way to set redirectURI based on some conditional logic? P.S. I am using react-router-dom so I will look into onRedirectCallback. Thanks for the help!

---

<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:** [April 6, 2021, 7:33pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/11 "2021-04-06T19:33:53Z")

</div>

I believe if you set up the `onRedirectCallback` it should redirect properly:

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

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

```

---

<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 25, 2021, 1:00pm UTC](https://community.auth0.com/t/how-to-redirect-to-a-different-page-based-on-signup-vs-login-screen/60258/12 "2021-06-25T13:00:17Z")

</div>

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