Simple Way to Log Out a User From All Browser Tabs
Developers will often want to logout/login a user automatically from all the open tabs/windows.
Let's say you are developing a Single Page Application using realm-web
JS SDK.
A user journey of the app will look like this: A user logs in with app.logIn(credentials)
, and opens multiple tabs/windows on the browser. Then the user clicks the "Log out" button inside one of the tabs, and switches to another tab. The app UI remains the same, but http requests will fail.
Although you might think it's a problem that each developer should tackle with, please consider to provide a native solution in realm-web
, if you think it's a common usecase for modern internet users.
JFYI, one of the solutions would be listening to changes of LocalStorage by window.addEventListener("storage")
, and it looks relatively simple to achieve:https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa