delete token from localstorage on closing tab code example
Example: How to clear localStorage when browser/tab is closing
window.addEventListener("beforeunload", () => localStorage.removeItem('storageVariable'));
window.addEventListener("beforeunload", () => localStorage.removeItem('storageVariable'));