Logout then login and redirect to url

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:

const auth0 = useAuth0()
            onClick={ () => {
               {redirect_uri: '/xyz'})
            Login to another account

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

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 documentation.

I hope this helps!

Please let me know how this works for you.


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…

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