Reputation: 106
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.
Upvotes: 3
Views: 935
Reputation: 17956
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.
Upvotes: 2