Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logout on browser close

Is there any way to logout on browser close while using jwt token in local storage for authentication in MeanStack application.

I have used beforeunload but it is called on refresh and few other events as well.

like image 560
Fadioo Avatar asked May 26 '26 08:05

Fadioo


1 Answers

You could use sessionStorage instead of localStorage. The only difference is that sessionStorage is only meant to survive the current browser session. Another option would be to store your application state in memory (in a variable) and it will be gone on close.

like image 77
cchamberlain Avatar answered May 27 '26 20:05

cchamberlain