How to log out of Auth0 on tab/window close

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?

Hey there!

Sorry for such a delayed response! We’re doing our best in providing you with the best developer support experience out there but sometimes our bandwidth is just not enough for all the questions coming in. Sorry for the inconvenience!

Can you let us know if you still require further assistance from us?

Thanks for reopening the issue. We are blocked with this issue and need this functionality by next week. Any suggestions will be helpful.

Hey there!

Let me consult it and get back to you shortly! Can you just tell me what SDK / framework of ours you use so we can potentially tailor the solution?

We are trying to redirect the user to Auth0 api to logoutfrom auth0 session
https://<Auth0_domain>/v2/logout

1 Like

Thank you for providing that context! Will get back to you soon!

I would like to know hot to do this as well.

How do we log out of Auth0 when the user closed the browser? Or is this not possible?

Hey there!

Managed to do some digging in your community forum and found this:

Apart from what ttchuah said in his first message this thread should give you the guidance how the thing with closing tab/window works from our side.