# Clear auth0 session when error occur on the callback action method

**URL:** <https://community.auth0.com/t/clear-auth0-session-when-error-occur-on-the-callback-action-method/33209>\
**Category:** Get Help\
**Tags:** logout, auth0\
**Created:** [November 1, 2019, 2:58pm UTC](https://community.auth0.com/t/clear-auth0-session-when-error-occur-on-the-callback-action-method/33209 "2019-11-01T14:58:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijay.tanavade](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vijay.tanavade/32/12799_2.png) [@vijay.tanavade](https://community.auth0.com/u/vijay.tanavade)\
**Post date:** [November 1, 2019, 2:58pm UTC](https://community.auth0.com/t/clear-auth0-session-when-error-occur-on-the-callback-action-method/33209/1 "2019-11-01T14:58:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [November 26, 2019, 5:49pm UTC](https://community.auth0.com/t/clear-auth0-session-when-error-occur-on-the-callback-action-method/33209/2 "2019-11-26T17:49:38Z")

</div>

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!

> **[Logout](https://auth0.com/docs/authenticate/login/logout)**
>
> Describes how logout works with Auth0.

---

<div class="post-metadata">

**Author:** ![maksym.somushkin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/maksym.somushkin/32/37955_2.png) [@maksym.somushkin](https://community.auth0.com/u/maksym.somushkin)\
**Post date:** [June 10, 2022, 12:24pm UTC](https://community.auth0.com/t/clear-auth0-session-when-error-occur-on-the-callback-action-method/33209/3 "2022-06-10T12:24:57Z")

</div>

Hey! Did you find a solution?

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [June 10, 2022, 6:10pm UTC](https://community.auth0.com/t/clear-auth0-session-when-error-occur-on-the-callback-action-method/33209/4 "2022-06-10T18:10:35Z")

</div>

@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](https://auth0.com/docs/authenticate/login/logout/redirect-users-after-logout)

---

<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:** [January 8, 2024, 1:07pm UTC](https://community.auth0.com/t/clear-auth0-session-when-error-occur-on-the-callback-action-method/33209/5 "2024-01-08T13:07:19Z")

</div>

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