Clear auth0 session when error occur on the callback action method

Hi, if there is an error that occurred in the callback action method after the user enters credentials and hits the login button, we are throwing the user to an error page. However, when the user again select the login URL in the same browser, they don’t redirect to login page, instead, it goes in the callback method again and throws the same error. how do we clear the auth0 session before throwing the user to the error page? We don’t want to redirect to logout page to clear the session.

Hey there @vijay.tanavade, I apologize for the delay in response!

We have some terrific documentation on logging out users from Auth0 and your application. When you get a chance give it a look below and let me know if you have any questions, thanks!

Hey! Did you find a solution?

@maksym.somushkin The original poster states they “don’t want to redirect to logout page to clear the session”. I don’t see any other way to do this in Auth0, as there is no way to programmatically end a user’s session from their APIs. Is that true for you as well?

If not, the solution would be to send the user to the /v2/logout URL with a returnTo query parameter of the error page. This will ensure that the user’s session is terminated on Auth0’s end and the user will land on the desired error page. You will need to whitelist the returnTo url on the application or tenant level.

More info in these docs

1 Like