After logging out how can I redirect the user back to the Auth0 login page?

I am creating an Angular 7 single page application and I am using Auth0 to log in. When the user clicks logout in my application I want the user to be logged out of the auth0 server and then redirect back to auth0 login page.

The tutorial I am currently following suggests that I should redirect back to a component in my application with a login button, and from there the user clicks log in and it sends me to the auth0 login page.

I understand I should be doing something like what I have below.

window.location.href=‘https://AUTH0LOGIN.com/v2/logout?returnTo=http%3A%2F%2FAUTH0LOGIN

Hi there @spmtest, as described in our Logout documentation, you redirect the user after a successful logout. Here is a excerpt from that documentation below:

To redirect a user after logout, add a returnTo querystring parameter with the target URL as the value. We suggest that you encode the target URL being passed in. For example, to redirect the user to http://www.example.com after logout, you can make the following request:

https://YOUR_AUTH0_DOMAIN/v2/logout?returnTo=http%3A%2F%2Fwww.example.com

You will need to add the non-encoded returnTo URL (for these examples, it is http://www.example.com ) as an Allowed Logout URLs in one of two places:

  • For logout requests that do not include the client_id parameter, such as:
https://YOUR_AUTH0_DOMAIN/v2/logout?returnTo=http%3A%2F%2Fwww.example.com

you must add the returnTo URL (for example http://www.example.com ) to the Allowed Logout URLs list in the Advanced tab of your Tenant Settings. See Set the Allowed Logout URLs at the Tenant Level for more information.

  • For logout requests that include the client_id parameter, such as:
https://YOUR_AUTH0_DOMAIN/v2/logout?returnTo=http%3A%2F%2Fwww.example.com&client_id=CLIENT_ID

you must add the returnTo URL (for example http://www.example.com ) to the Allowed Logout URLs list in the Settings tab of your Auth0 app that is associated with the specified CLIENT_ID . See Set the Allowed Logout URLs at the Application Level for more information.

However if by chance I am misunderstanding your desired result please let me know as I am happy to help! Thanks!

Hey @James.Morrison, thanks for the response. I believe you slightly misunderstood my desired result.

When the user clicks logout I want to redirect the user to the following Auth0 Login page.

I’m not sure what the correct return url would be to allow the user to login.

1 Like

Hi @spmtest,

James can probably better answer this than I can, but I believe redirecting back to the hosted login page (which seems to be what you are demonstrating) is a bad idea. The hosted login page URL has a state parameter, and that parameter is time limited. After a while the URL becomes invalid and the user will get an error if they try logging in.

2 Likes

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