#4390

fix(gui): a request the server no longer accepts signs the tab out locally

Openjfcastro92wants to merge intofrom

A request the server no longer accepts now signs the tab out locally instead of ending the session. For PUT-2260.

What

window.handle401 is the shared 401 handler behind about fifteen $.ajax call sites. Until now, any 401 that wasn't a reauth_required ran the full window.logout(), which POSTs /logout and ends the session on the server. That takes everything registered under the session with it, push devices included, for what is often a token the server simply stopped accepting (expired, or minted for another session) while the session itself is fine.

Now:

  • A 401 outside the reauth flow calls window.sign_out_locally(): it drops the tab's token and user from storage, clears the cache, and reloads. The session cookie signs the tab back in when the session still holds, so nothing registered under the session is lost. When the session is gone, the reload lands on the sign-in page as before.
  • A second such 401 within a minute of that reload, in the same tab, runs the full window.logout(), so a session that keeps answering 401 still ends cleanly.
  • reauth_required keeps going to the reauth flow, unchanged.
  • A peer tab clearing the token is mirrored with the same local sign-out. That tab already ended the session if it meant to; mirroring it with another /logout added nothing.

Explicit sign-outs (the menu, the account dialogs) still use window.logout().

Tests

src/gui/src/helpers.handle401.test.js, five cases: a non-reauth 401 drops the token and reloads without logout() and keeps other local state; a reauth 401 goes to the reauth flow untouched; a 401 right after a local sign-out runs logout(); an old local sign-out is forgotten; a peer tab's sign-out is mirrored locally. Four of the five fail on the previous code.

GUI suite: 105 files, 1262 tests pass. Typecheck unchanged.

Not in this change

tokenChanged in initgui.js is computed after window.auth_token is reassigned, so it's always false; the follow-up whoami never runs. Left for a separate change, since it alters what happens at boot.