Auth0 Home Blog Docs

How to log out of Auth0 on tab/window close

logout
auth0
auth0js
#1

I have a React web app set up. It’s hooked up to a new tenant. Login/logout functionality all work.

I want to make it so that when the user closes their tab or browser, I log out of Auth0 as well. Normally I would accomplish logout by using the Auth0JS library’s logout method. I could call this method using the onbeforeunload event, I suppose, but I’m concerned that Auth0 won’t have a chance to finish the logout process before the window/tab closes.

Any suggestions?