Is it possible to auto logout a user from all opened tabs if that user sign out from one of the open tab in the browser in buddypress/wordpress.
Thanks!
So this depends a bit on what you mean:
The browser shares one session over all tabs/windows so you're either logged in or out everywhere. So when you log out you are actually logged out in all tabs. You just don't notice until you try to go somewhere else because, well, the open page doesn't just magically disappear from the browser view. But you can't go anywhere else from now on.
What you might also mean is that as soon as you log out in one tab all other pages open in other tabs/windows "close" immediately. This might be somewhat doable via JS, but may I ask what the point of this is? The user has already opened the page and seen it. Taking it away now doesn't really change anything anymore, right?
we can use Storage events to be notified when localStorage values are changed.
function storageChange (event) {
if(event.key === 'logged_in') {
alert('Logged in: ' + event.newValue)
}
}
window.addEventListener('storage', storageChange, false)
If, for example, one of the tabs logs out:
window.localStorage.setItem('logged_in', false)
Then all other tabs will receive a StorageEvent, and an alert will appear:
Logged in: false