# Logout is not happening on Browser/Tab close

**URL:** <https://community.auth0.com/t/logout-is-not-happening-on-browser-tab-close/93862>\
**Category:** Get Help\
**Tags:** jwt, logout, auth0\
**Created:** [November 7, 2022, 5:17pm UTC](https://community.auth0.com/t/logout-is-not-happening-on-browser-tab-close/93862 "2022-11-07T17:17:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vjai29](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vjai29/32/41123_2.png) [@vjai29](https://community.auth0.com/u/vjai29)\
**Post date:** [November 7, 2022, 5:17pm UTC](https://community.auth0.com/t/logout-is-not-happening-on-browser-tab-close/93862/1 "2022-11-07T17:17:56Z")

</div>

Hi fellas,

we are facing an issue when we try to logout of single page react application , below is the code used to call logout function. let me know if you need further info.

const { logout } = useAuth0();  
useEffect(() =\> {  
const handleTabClose = (event: { preventDefault: () =\> void; returnValue: string; }) =\> {  
localStorage.removeItem(‘id\_token’);  
logout();  
event.preventDefault();  
console.log(‘beforeunload event triggered’);  
return (event.returnValue = ‘Are you sure you want to exit?’);  
};

```
   window.addEventListener('beforeunload', handleTabClose);
    return () => {
        window.removeEventListener('beforeunload', handleTabClose);
    };
}, []);

```

---

<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 11, 2024, 9:36pm UTC](https://community.auth0.com/t/logout-is-not-happening-on-browser-tab-close/93862/2 "2024-12-11T21:36:12Z")

</div>

Hello @vjai29!

I understand you would like to logout when the browser or tab is closed. This can be achieved using [Non-Persistent Sessions](https://auth0.com/docs/manage-users/sessions/non-persistent-sessions). This is only available on certain browsers and comes with its own limitations. Please read the documentation and see if it fixes your issue.

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:** [December 25, 2024, 9:36pm UTC](https://community.auth0.com/t/logout-is-not-happening-on-browser-tab-close/93862/3 "2024-12-25T21:36:14Z")

</div>

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