Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Web Security TippsIntroducing the new Confluence integration with Google Chat(22.09.2026 um 19:40 Uhr)
Web Security TippsQuick notes in Take notes for me(22.09.2026 um 21:31 Uhr)
Sichere ProgrammierungSecurity improvements for SSH(22.09.2026 um 16:11 Uhr)
Sichere ProgrammierungKI-Akzeptanz: Wie Rewe digital einfach nur den Chatbot umbenannte(22.09.2026 um 18:00 Uhr)
Sichere ProgrammierungClaude Opus 5.5: Keeping safety ahead of capabilities(22.09.2026 um 20:59 Uhr)
Sichere ProgrammierungYour Terraform Monolith Isn't Too Big. It's Tightly Coupled.(22.09.2026 um 21:00 Uhr)
Sichere ProgrammierungMy PR got merged into Mike — OSS Legal AI Platform 🎉(22.09.2026 um 21:34 Uhr)
Sichere ProgrammierungStop Writing JavaScript To Fix `100vh` On Mobile(22.09.2026 um 21:35 Uhr)
Sichere ProgrammierungNext.js proxy.ts Explained (with Cheat Sheet)(22.09.2026 um 21:36 Uhr)
Web Security TippsIntroducing the new Confluence integration with Google Chat(22.09.2026 um 19:40 Uhr)
Web Security TippsQuick notes in Take notes for me(22.09.2026 um 21:31 Uhr)
Sichere ProgrammierungSecurity improvements for SSH(22.09.2026 um 16:11 Uhr)
Sichere ProgrammierungKI-Akzeptanz: Wie Rewe digital einfach nur den Chatbot umbenannte(22.09.2026 um 18:00 Uhr)
Sichere ProgrammierungClaude Opus 5.5: Keeping safety ahead of capabilities(22.09.2026 um 20:59 Uhr)
Sichere ProgrammierungYour Terraform Monolith Isn't Too Big. It's Tightly Coupled.(22.09.2026 um 21:00 Uhr)
Sichere ProgrammierungMy PR got merged into Mike — OSS Legal AI Platform 🎉(22.09.2026 um 21:34 Uhr)
Sichere ProgrammierungStop Writing JavaScript To Fix `100vh` On Mobile(22.09.2026 um 21:35 Uhr)
Sichere ProgrammierungNext.js proxy.ts Explained (with Cheat Sheet)(22.09.2026 um 21:36 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Syncing Multiple Tabs in a Browser Application

If you open the same application in multiple tabs on the same browser, sometimes it becomes really important to keep these tabs in sync. For example, think about your online banking portal. If you log in on one tab and then try to open the…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

If you open the same application in multiple tabs on the same browser, sometimes it becomes really important to keep these tabs in sync. For example, think about your online banking portal. If you log in on one tab and then try to open the same portal in another tab, the first tab will often show a “session expired” message or automatically log you out.



That's a classic case of tab synchronization.






The problem I faced



In my case, the issue was auth syncing.



When the application was opened in multiple tabs, if the user logged out in one tab, the other tabs still tried to use the expired access token. Since the token was no longer valid, all API calls in those tabs failed until the user manually refreshed.






The solution



The idea is simple:




  1. Use localStorage as a shared state between tabs (since it is accessible across all the tabs of the same origin).

  2. Keep a special key (let's call it changeInAuth) in localStorage that updates whenever login or logout happens.

  3. In every tab, listen for changes to this key using the storage event. When a change is detected, clear any invalid data from sessionStorage and reload the page so that the tabs fetches fresh tokens and user data.



Step 1: Add a storage event listener in App.tsx




useEffect(() => {
const handleLocalStorageChange = (event: StorageEvent) => {
// Check if the auth key changed
if (event.key === "changeInAuth") {
// Clear session data
sessionStorage.clear();

// Refresh the page
window.location.reload();
}
};

window.addEventListener("storage", handleLocalStorageChange);

// Always clean up event listeners
return () => {
window.removeEventListener("storage", handleLocalStorageChange);
};
}, []);







Here, we're telling the browser:




"If any tab updates the changeInAuth key in localStorage, reload this tab."




Step 2: Update localStorage during login




const login = async (userCreds) => {
try {
// Call authentication API
// Save tokens, user info, etc. in sessionStorage or cookies

// Trigger sync event for other tabs
localStorage.setItem("changeInAuth", Date.now().toString());
} catch (error) {
console.error("Login failed:", error);
}
};






Step 3: Update localStorage during logout




const logout = async () => {
// Call logout API
// Clear tokens, user info, and sessionStorage/cookies

// Trigger sync event for other tabs
localStorage.setItem("changeInAuth", Date.now().toString());
};









How it works




  • Whenever login or logout happens, a unique timestamp is stored in localStorage under the key changeInAuth.

  • All tabs are listening for changes to this key.

  • When a change is detected, tabs clear old session data and reload.

  • After reload, they fetch fresh tokens and sync with the backend.



This way, the application can:




  1. Keep all tabs sync.

  2. Handle single-user sessions properly

  3. Automatically switch to the correct user when someone logs in/out.






Final thoughts



The storage event is a very handy browser feature, and in many cases, a few lines of code are enough to solve what could otherwise be a very frustrating problem.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Syncing Multiple Tabs in a Browser Application

Thematisch verwandte Begriffe: Syncing, Multiple, Tabs, Browser · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-77259 | MCP Atlassian is a Model Context Protocol (MCP) server for Atlassian pro…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick