Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Adding SSE Live Updates Logged Out Users With Multiple Tabs: Fixing the Refresh Token Race

Everything worked until we shipped live updates We added live updates to our app with Server-Sent Events (SSE). When someone approves a request, every other user sees it right away, with no page reload. It worked well in testing. Then a bug report came in: "I had the app open in two windows. I didn't click anything, and suddenly both windows showed the login page." It only happened with two or…

The bug report surfaced after live updates were added to the app using Server-Sent Events (SSE). Users encountered a scenario where opening the app in multiple windows resulted in both windows logging them out. The issue persisted even though no changes were made to the login code. The setup involved storing access and refresh tokens in cookies, with all tabs of the same site sharing the same cookies.

When a 401 error occurred, the frontend would call POST /users/refresh, asking the backend to retrieve new tokens and set new cookies. However, the solution was complicated by the fact that Keycloak had refresh token rotation enabled, meaning each refresh returned a new refresh token, invalidating the old one. When two or more windows were open, the streams ended simultaneously due to sharing the same token, causing both windows to reconnect and call /refresh at the same time.

This led to the old refresh token being reused, resulting in the session being dropped by Keycloak. The fix involved implementing a mechanism for tabs to take turns refreshing tokens, utilizing the Web Locks API to ensure only one tab refreshed at a time. A tab that waited for the lock would check if another tab had refreshed while it was waiting using localStorage to store the last refresh timestamp.

If the shared token had been refreshed, the second tab would skip refreshing. This approach prevented multiple refreshes from occurring simultaneously and avoided the logout issue. The same timeline applied, with only one refresh needed instead of two. Background tabs, which were closed after 30 seconds of inactivity, remained logged in and refreshed when reopened using the same lock mechanism. The implementation kept tabs logged in and prevented logout even in hidden tabs.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

I writes code fast, so I use skills to build the gates that catch the bugs unit tests miss

Why green unit tests stopped giving me confidence When a coding agent can generate a new component or reactive helper in 20 seconds, writing code is no longer the bottleneck.

  • Introduces 4-skill workflow to catch bugs missed by unit tests
  • Spec skill defines measurable success criteria and state boundaries
  • Formal-verification skill catches silent bugs in reactive graphs and state machines

I built a waitlist for Calendly that works on the free plan

Calendly needs a waitlist and it's been asked for since 2024! When a client cancels, that slot usually just sits empty, unless the coach or tutor happens to remember who wanted an earlier time.

  • Ray developed NextUp, a waitlist solution for Calendly's free plan.
  • NextUp integrates with Calendly, allowing clients to view and select available appointment times.

A blog post could run commands on your laptop through MCP Inspector. What localhost doesn't protect

This is the request Oligo Security used to show CVE-2025-49596: http://0.0.0.0:6277/sse?transportType=stdio&command=touch&args=%2Ftmp%2Fexploited-from-the-browser Port 6277 is where MCP Inspector's…

  • Attackers can run processes on laptop via MCP Inspector proxy.
  • Proxy listens on port 6277 by default, no token needed before v0.14.1.
  • MCP Inspector patched vulnerability in v0.14.1 with session token and Origin header check.

Why a coding agent's edit-test loop should not wait on CI

There is a pattern that shows up when a team first lets coding agents work on real repositories without running them on anyone's laptop.

  • Agent edit-test loop incurs full CI pipeline cost per iteration
  • Agent reads CI logs, not directly from machine output
  • Split CI checks into code changes, full suite, and required checks

More from Tuesday, 1 December 2026 →