The React website has following requirements:
- Stay logged in when opening a page of the current website in new tab.
- Log out if browser is closed and reopened.
- Stay logged in on page refresh.
- IE11 support :(.
If I keep auth token in sessionStorage, it meets the 2 requirement but not the 1.
If I use localStorage - 1 but not 2.
If I use:
window.onunload = () => {
localStorage.removeItem('authtoken');
};
it meets 1 and 2 conditions but it also clears storage when I refresh the page which shouldn't happen too!
This solution to check if the page is refreshing can't be used in IE11 https://stackoverflow.com/a/53307588/12994741
So how should I keep the auth token? Any way to make it? Maybe it's possible to prevent unload event on refreshing in React?