Fadioo
Fadioo

Reputation: 106

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.

Upvotes: 3

Views: 935

Answers (1)

cchamberlain
cchamberlain

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

Related Questions