Logout is not happening on Browser/Tab close

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);
    };
}, []);
2 Likes

Hello @vjai29!

I understand you would like to logout when the browser or tab is closed. This can be achieved using 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