I am working on React Js Application, I am using Localstorage for managing the Application Token. And i want, when user close the TAB, localsotorage will get empty. For that i am using beforeunload.
window.addEventListener("beforeunload", () => localStorage.clear());
But this things also call when i refresh the browser. I want to prevent it, that when user refresh the browser, localstorage not clear. How can i achive it?
I can not want to use sessionStorage because i need to communicate token/record with other tabs as well.