# V2/logout not clearing auth0 session cookies

**URL:** <https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327>\
**Category:** Get Help\
**Tags:** cookie, logout, auth0\
**Created:** [September 8, 2021, 10:05pm UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327 "2021-09-08T22:05:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alex0/32/27029_2.png) [@Alex0](https://community.auth0.com/u/Alex0)\
**Post date:** [September 8, 2021, 10:05pm UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/1 "2021-09-08T22:05:15Z")

</div>

Hi there,

I have a react SPA using auth0 SP with a SAML auth0 Idp for authentication. The login authentication is working great. the problem is the logout, when users click on a logout button, it triggers the `logout` auth0 hook, which i think It calls the `v2/logout` endpoint, and it redirects the users to the logout callback, the problem is that the auth0 cookies are not being cleared out, so if the user tries to log in again, it is automatically signed in without prompting credentials. When I manually clean the cookies after each logout the app behaves the way it’s supposed to.

I tried setting the session expiration from 36000 to 60 seconds, but that didn’t help. I also tried using the `v2/logout` as shown here [Authentication API Explorer](https://auth0.com/docs/api/authentication#logout), but it didnt work.

---

<div class="post-metadata">

**Author:** ![karuissobusy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/karuissobusy/32/80340_2.png) [@karuissobusy](https://community.auth0.com/u/karuissobusy)\
**Post date:** [September 8, 2021, 11:57pm UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/2 "2021-09-08T23:57:53Z")

</div>

Hi Alex,

Just letting you know how we do logout which may help in your case.  
https://${context.request.hostname}/v2/logout?client\_id=${context.clientID}&returnTo=https:///AuthzFail.htm

Instead hardcoding the Auth0 domain name in logout url we are reading from context object so we are sure that we don’t send to a different Auth0 Tenant/Instance (we have sandbox and prod in our org). And passing the client\_id parameter with returnTo URL, beacuse the returnTo needs to be whitelisted logout url at client level. I think if we add the returnTo url at tenant level logout whitelisting we can avoid client\_id parameter.

Cheers,  
Karthick.

---

<div class="post-metadata">

**Author:** ![Alex0](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alex0/32/27029_2.png) [@Alex0](https://community.auth0.com/u/Alex0)\
**Post date:** [September 9, 2021, 12:37am UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/3 "2021-09-09T00:37:24Z")

</div>

Hi Karuissobusy,

Thanks for your answer, unfortunately, that doesn’t work in my case, because the auth0 hook is already building the correct logout url to match the Auth0 tenant/client, and I can verify the logout was successful in the auth0 monitoring logs, the problem is that the auth0 session cookies are not cleared in the browser, therefore the user is not being asked for credentials when they press the login button, and as this doc [https://auth0.com/docs/login/logout/log-users-out-of-auth0](https://auth0.com/docs/login/logout/log-users-out-of-auth0) suggests, on logout the auth0 cookies will be cleared, am I missing something here?

---

<div class="post-metadata">

**Author:** ![connor1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/connor1/32/34409_2.png) [@connor1](https://community.auth0.com/u/connor1)\
**Post date:** [February 2, 2022, 12:08am UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/4 "2022-02-02T00:08:53Z")

</div>

Hi Alex, did you figure this out? I am having the same issue.

---

<div class="post-metadata">

**Author:** ![bend](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bend/32/5516_2.png) [@bend](https://community.auth0.com/u/bend)\
**Post date:** [March 22, 2022, 1:06am UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/5 "2022-03-22T01:06:21Z")

</div>

Seeing the same behaviour here. We are in the middle of moving from auth0.js to auth0-spa.js in our angular application. Logging out via an iframe was working when using auth0.js but stopped after to switching to auth0-spa.js. It appears the logout is actioned in the auth0 logs but the cookies remain.  
As an experiment I loaded the logout URL in a new window and it correctly cleared the cookies so it appears to be an issue with iframe only.

---

<div class="post-metadata">

**Author:** ![bend](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bend/32/5516_2.png) [@bend](https://community.auth0.com/u/bend)\
**Post date:** [March 22, 2022, 1:55am UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/6 "2022-03-22T01:55:52Z")

</div>

Appears to be related to Chrome blocking third party cookies in incognito mode. Allowing all cookies in the chrome setting restored the expected behaviour. Not really how to proceed, since if the user has disallowed third party cookies then the logout in iframe solution will never work and its also difficult to detect it didn’t work so hard to recover from.

---

<div class="post-metadata">

**Author:** ![mgeovany](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mgeovany/32/49452_2.png) [@mgeovany](https://community.auth0.com/u/mgeovany)\
**Post date:** [July 25, 2024, 10:03pm UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/7 "2024-07-25T22:03:35Z")

</div>

Any solution to this?

---

<div class="post-metadata">

**Author:** ![vmuyvico](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vmuyvico/32/74030_2.png) [@vmuyvico](https://community.auth0.com/u/vmuyvico)\
**Post date:** [April 1, 2025, 8:21pm UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/8 "2025-04-01T20:21:49Z")

</div>

This took me some time too. If you’re on web, simply override the handleLogout method and pass `federated: true`.

On your routes.js

```auto
import { handleAuth, handleLogin, handleLogout } from '@auth0/nextjs-auth0';

export const GET = handleAuth({
  logout: async (req) => {
    return handleLogout(req, {
      federated: true,
      returnTo: 'http://localhost:3000' // Replace with your desired post-logout URL
    });
  }
});

```

---

<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:** [April 15, 2025, 8:22pm UTC](https://community.auth0.com/t/v2-logout-not-clearing-auth0-session-cookies/69327/9 "2025-04-15T20:22:40Z")

</div>

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