I am using this code,
useEffect(() => {
window.addEventListener("beforeunload",() => {
localStorage.removeItem("token")
})
})
but my requirement is to clear this token only when all tabs get closed or the browser itself gets closed, but this event is occurring for even page refresh, so is there any possible way to block this part of code when the page gets refreshed and only execute when tabs or browser gets closed.
Any help would be highly appreciable, thanks in advance!!!