Back URL on logout and redirect to back url after login

Hello there.
Scenario:

  1. User going to page /topics/123
  2. User logout coz of session timeout and now see page: /login?back_url=/topics/123
  3. User login again and auto-redirected to /topics/123 page

Question:
What is most right way to do that via auth0? The most big problem that auth0 redirected user from react to auth0 site and only one way to save last url will be put this in localStorage.

Session cookie or localStorage sounds like a valid approach, I’d also go that route. After the callback from Auth0 back to your site, read out the localStorage or cookie and make the further redirect to the topic page again.


There is another option, but I don’t see much of a benefit there (esp. because I’d like to avoid wildcards in callback url patterns):

You could allow for a callback url with a wildcard like:

https://yourdomain.com/callback?back_url=*

in your client applications settings in the Auth0 dashboard, and then, when the user got logged out and needs to re-login, pass that as redirect_uri parameter accordingly in the authorization request to Auth0, like:

https://yourdomain.com/callback?back_url=/topics/123

Once the callback happens, you handle the redirect based on that parameter.

@aevlanov Updated answer with an alternative, though I wouldn’t consider it being better.

1 Like