# How do i log a user out of auth0 on window close?

**URL:** <https://community.auth0.com/t/how-do-i-log-a-user-out-of-auth0-on-window-close/59465>\
**Category:** Get Help\
**Tags:** logout\
**Created:** [March 15, 2021, 4:47pm UTC](https://community.auth0.com/t/how-do-i-log-a-user-out-of-auth0-on-window-close/59465 "2021-03-15T16:47:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay2](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jay2](https://community.auth0.com/u/jay2)\
**Post date:** [March 15, 2021, 4:47pm UTC](https://community.auth0.com/t/how-do-i-log-a-user-out-of-auth0-on-window-close/59465/1 "2021-03-15T16:47:28Z")

</div>

Hello all, ill just start by saying i have read other posts on this forum about this subject and non of them help (i have also read the docs and there is nothing pointing me to a solution on there)

I am dealing with very sensitive data and for this reason when the browser or tab is closed, users should be logged out of both my application and not be able to call my API’s. i am using [nextjs-auth0](https://github.com/auth0/nextjs-auth0) with default settings.

As far as i can tell (from looking at the library’s code) the `/api/auth/logout` endpoint will clear the **Application Session Layer** however because i am unable to clear the ’ **Auth0 Session Layer** when the user opens the browser and visits the website again the auth0 tenant still thinks the user is logged in and will just set the cookie from what i now consider to be the last session that should of ended (i tested this by deleting the cookie from the browser and refreshing the page)

i use a javascript event to detect when the browser closes and tried using fetch to pragmatically send a request to the logout url “https://YOUR\_DOMAIN/v2/logout” in order to log the user out of auth0 however this does not work.

has anyone got any ideas how my use-case can be implemented (without using short lived tokens as this does not solve my issue)

---

<div class="post-metadata">

**Author:** ![jay2](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jay2](https://community.auth0.com/u/jay2)\
**Post date:** [March 15, 2021, 4:49pm UTC](https://community.auth0.com/t/how-do-i-log-a-user-out-of-auth0-on-window-close/59465/2 "2021-03-15T16:49:23Z")

</div>

EDIT: This is a dealbreaker for me using auth0 if it is not possible to force log out a user on browser close i will need to find an alternative.

---

<div class="post-metadata">

**Author:** ![eldard](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eldard/32/39726_2.png) [@eldard](https://community.auth0.com/u/eldard)\
**Post date:** [September 4, 2022, 3:13pm UTC](https://community.auth0.com/t/how-do-i-log-a-user-out-of-auth0-on-window-close/59465/3 "2022-09-04T15:13:47Z")

</div>

Same problem here, I would love to hear back from Auth0 about this manner 🙂

---

<div class="post-metadata">

**Author:** ![alex.brett](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alex.brett/32/60157_2.png) [@alex.brett](https://community.auth0.com/u/alex.brett)\
**Post date:** [December 10, 2024, 7:26pm UTC](https://community.auth0.com/t/how-do-i-log-a-user-out-of-auth0-on-window-close/59465/4 "2024-12-10T19:26:25Z")

</div>

Hello @jay2!

Using Non-persistent sessions will give you the desired result. Here are some docs that explain how they work in Auth0. Please give this a read.

> **[Non-Persistent Sessions](https://auth0.com/docs/manage-users/sessions/non-persistent-sessions)**
>
> Describes non-persistent sessions available with Auth0.

I hope this helps!

Best,  
Alex

---

<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:** [March 18, 2025, 12:15pm UTC](https://community.auth0.com/t/how-do-i-log-a-user-out-of-auth0-on-window-close/59465/5 "2025-03-18T12:15:50Z")

</div>

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