I think beforeunload also works when the user refreshes the page not just when they close the page or navigate away. You can try storing the organizationIdentifier in localStorage when the user first opens the website. Then create an if condition to compare the current organization using (window.location.pathname) with the one stored in localStorage. If they’re not the same call sessionStorage.clear() and then update the value in localStorage. Hope it will work for u !