All posts
EngineeringNovember 17, 2026 · The Ubriot team · 4 min read

Three dashboard pages kept sending the token from the day you signed in

Analytics, billing and release health bypassed our shared API client, so a silent token refresh left them returning 401 until you signed in again. Here is how that happens, the fix, and the check we added to catch the next one.

The Ubriot dashboard signs you in with a short-lived access token and a longer-lived refresh token. When a request comes back 401, our shared API client exchanges the refresh token for a new pair and retries the request once. If several requests fail at the same moment, they share one refresh instead of each spending the refresh token. If the refresh itself is refused, the session is cleared and you land on the sign-in page. That logic works, and most of the dashboard has never noticed the access token expiring.

Three pages did notice. Build analytics, billing and release health returned 401 once the access token had been refreshed in the background, and they kept returning it until the person signed in again. Upgrading a plan and cancelling one failed the same way. It is the worst kind of session bug: nothing is wrong with the account, the rest of the dashboard works, and the only visible symptom is a page that will not load its data.

A second way to call the same API

Those three pages did not use the shared client. Each had its own request code that read the access token out of the saved sign-in record and attached it by hand. That is a perfectly reasonable thing to write the first time you build a page, and it works for as long as the token you saved at sign-in is still the token the server accepts.

Once the shared client refreshed the token, it stored the new one. The three pages kept reading the old copy from the saved user object, so every request they made carried a token the server had already moved past. The refresh was happening. These pages were opting out of it.

The fix is to remove the second path

We did not patch each page to refresh for itself. That would have made three more copies of retry logic to keep in step with the first. The pages now go through the shared client, which sends the current token, refreshes once on a 401 and retries. A failed refresh ends the session on every path, not only some of them. We also made the saved user carry the refreshed token, so anything that still reads the stored record sees the same value the client is using.

Billing needed the same care as the read-only pages, and arguably more. A plan change that fails with a 401 looks like a payment problem to the person clicking it. Sending it through the shared client means the retry happens before they ever see an error.

The streaming request had the same flaw

Later the same day we found the same pattern in one more place. The AI assistant in the dashboard streams its answer, and the stream used a raw fetch with the token from sign-in, so it failed once that token had expired. Streaming makes this easy to miss, because a streamed response does not fit the usual request and response wrappers. The shared client had a fetch-style entry point for exactly this reason, and the stream simply had not been moved onto it.

The stream now uses that entry point. The part worth knowing is that the retry is safe because the 401 arrives before any of the answer does. We resend the same body with the new token, and the first byte the user sees comes from the second attempt. We would not retry a stream that had already started producing output.

Testing it

The tests for this write the failure down as a sequence. A request goes out with an expired token and gets a 401. One refresh call happens. The same request goes out again with the fresh token and succeeds. They assert that exactly one refresh was made, that the retry carried the same body, and that the saved user ends up holding the new token. For the stream, the test checks that the events from the retried response arrive in order.

Unit tests only cover the pages somebody remembers to test, though, and the stream turned out to be a fourth caller nobody had listed.

Making the next one loud

So we changed the browser smoke check as well. After signing in, it now visits analytics, billing and release health, and it fails if any data request on a signed-in page returns a 401 or a server error. A page that goes blank because its request was rejected is no longer something we find out about from a customer.

If you maintain a dashboard with refresh tokens, the audit is short. Search for every place that reads the access token directly and attaches it by hand. Each hit is a request that will break the first time a refresh happens somewhere else. Either route it through the one client that knows how to refresh, or have a reason written down for why it cannot.

Try Ubriot AI

React Native CI/CD from one CLI.

Get started