# Logout then login and redirect to url

**URL:** <https://community.auth0.com/t/logout-then-login-and-redirect-to-url/93269>\
**Category:** Get Help\
**Tags:** api, logout, login, auth0\
**Created:** [October 27, 2022, 10:26pm UTC](https://community.auth0.com/t/logout-then-login-and-redirect-to-url/93269 "2022-10-27T22:26:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marid](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@marid](https://community.auth0.com/u/marid)\
**Post date:** [October 27, 2022, 10:26pm UTC](https://community.auth0.com/t/logout-then-login-and-redirect-to-url/93269/1 "2022-10-27T22:26:14Z")

</div>

Hi. I’m trying to accomplish the following:

- user navigates to url /abc
- user clicks a button on page /abc
- user gets logged out and is prompted to login
- once logged in, user is redirected to another page /xyz

I’m doing:

```auto
const auth0 = useAuth0()
<btn
            onClick={ () => {
              auth0.logout();
              auth0.loginWithRedirect({ 
               {redirect_uri: '/xyz'})
          >
            Login to another account
          </btn>

```

However the logout is getting cancelled by the loginWithRedirect call. Without loginWithRedirect the logout works just fine. How can I fix this?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 27, 2022, 11:21pm UTC](https://community.auth0.com/t/logout-then-login-and-redirect-to-url/93269/3 "2022-10-27T23:21:56Z")

</div>

Hi @marid,

Welcome to the Auth0 Community!

I understand that you have issues with calling both the `logout()` and `loginWithRedirect()` functions.

From what I understand, this sounds like forcing re-authentication. In this case, you could call the `loginWithRedirect()` function with the `prompt=login` parameter.

This should force reauthentication as described in our [Force Reauthentication in OIDC](https://auth0.com/docs/authenticate/login/max-age-reauthentication) documentation.

I hope this helps!

Please let me know how this works for you.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![marid](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@marid](https://community.auth0.com/u/marid)\
**Post date:** [October 29, 2022, 1:12am UTC](https://community.auth0.com/t/logout-then-login-and-redirect-to-url/93269/4 "2022-10-29T01:12:19Z")

</div>

thank you rueben, but if I understand it correctly, `loginWithRedirect` with a `prompt=login` won’t end the user session. What I want is to first end the current user session (aka logout) and after that automatically redirect them to login and, once they log in, automatically redirect to the `/xyz` url . How can I do that?

'Update: ok I got it working, just not sure how to validate the reauthentication using auth\_time…

---

<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:** [November 12, 2022, 1:12am UTC](https://community.auth0.com/t/logout-then-login-and-redirect-to-url/93269/5 "2022-11-12T01:12:32Z")

</div>

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