Picture this: you’re using your favorite web app. You have three tabs open — one with reports, one editing a document, and one checking settings.
In the settings tab, you click Logout.
You think you’re done… but when you switch back to the other tabs, surprise! They still look logged in. You can click buttons, type in forms, and maybe even see private data.
This is the multi-tab session problem. And it’s more common than you think.
Why This Problem Happens
Browsers don't automatically tell every tab that you've logged out in another one.
Yes, cookies are shared across tabs, but your app’s JavaScript in each tab doesn’t know what happened until it talks to the server again.
So you end with:
- Tab A -> You're officially logged out (server knows, UI knows)
- Tab B -> Your UI doesn't know what happened and hasn't updated yet
Result: a weird, broken state that can confuse users or even expose private data.
Real-Life Example
Imagine a design tool with a subscription:
- Tab 1: You’re using a premium feature.
- Tab 2: You cancel your subscription in settings.
- What happens? Tab 1 still lets you use the premium feature until refresh.
Bad for business (free features) and bad for the user (sudden “Access Denied” when saving). Everyone loses.
How Developers Fix It
The trick is simple: make your tabs talk to each other.
Step 1: When something important changes (like logging out), store that change in localStorage
.
Step 2: Add a listener in every tab that watches for these changes:
window.addEventListener('storage', (event) => {
// Check for our specific key and that it was set to 'loggedOut'
if (event.key === 'authStatus' && event.newValue === 'loggedOut') {
// Could reload, redirect, or update state
window.location.reload();
}
});
Now, if one tab logs out and sets authStatus = 'loggedOut'
, the other tabs instantly know.
Better approach: instead of always reloading (which can be annoying), you can show a message like: "You’ve been logged out" → redirect to login page.
Things to Remember
- This only works for the same domain (yourapp.com).
- The storage event fires only in other tabs, not the one that made the change.
- For some apps, you may also want to sync session data between tabs, but that’s extra work.
The Bottom Line
If you’re building a web app with accounts, don’t forget the multi-tab case. Users won’t thank you when it works… but they’ll notice when it doesn’t.
Because the only thing worse than a broken logout is working inside a ghost session that died 20 minutes ago. 👻
Top comments (14)
You can also use the Broadcast Channel API for this.
But I think if your storing keys in local storage it does make sense to just listen there.
Oh right! Broadcast Channel API works well too
I used local storage because most apps already store auth stuff there, so one listener handles logout and other auth changes.
But yes, if you only need logout sync, Broadcast Channel is simpler for sure..
Thanks for sharing!
Fwiw, most apps I've worked on don't store anything in local storage, and certainly not auth-related things!
lol right, in demos I've seen localStorage used a lot, but you're right, secure storage is safer:)
it's a notification, does not matter :D
I think the BroadcastChannel API is more appropriate for this case.
The moment you log out of Tab 1 and then log in to Tab 2, you're using a feature. Most of the things are refresh or server actions based. Like, logging into X or LinkedIn, then opening two tabs, T1 & T2. You log out from T1, and then T2, you're still active. The moment you try to like, comment, or rewatch something, that's a server action, and then it's not completed. Of course, you'll still enjoy those 3-4 minutes of free time/see whatever is in your viewport, but then it will mostly be refreshed soon.
Most of the websites have identified and fixed this. But the new-age vibecoded applications aren't, I'm just saying. Well you know, 😊
Exactly! Big platforms handle server-side validation well. The problem is newer apps that let you click around for minutes before realizing your session is dead:)
This post is mainly for devs who haven't dealt with this yet , better UX to sync logout immediately on the client side
Yes, smart devs are likely to test and find it out while building an app.
Big platforms -> lots of devs working together. In the end, it's all developers. Always have been
Great read!
Ah yes... the ghost session 👻 sneaky but deadly 😁
Thanks for sharing this! Super helpful — I never noticed this issue before.
I've found that localStorage can be blocked, so always use try/catch and preferably try the feature first, then note it in you global object, that local storage is NOT available
Some comments may only be visible to logged-in visitors. Sign in to view all comments.