Skip to content

fix(ui): sign-in returns to the page you were on, and the live socket follows the session (#3444, #3445, #3466) - #4069

Merged
webmixgamer merged 5 commits into
devfrom
feature/3444-login-return-path
Oct 30, 2026
Merged

webmixgamer merged 5 commits into
devfrom
feature/3444-login-return-path

Conversation

@webmixgamer

@webmixgamer webmixgamer commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Three symptoms found in the UI sweep (epic #3471, PR 6) share one gap: nothing on the way to /login said where the person had been, and nothing tied the real-time sockets to the platform session.

The class of problem this closes (#3445)

When a connection's authorization is fixed at connect time, the connection must be closed when the session it was authorized for ends. The SPA holds two /ws connections, and neither did that. The app-wide socket was never closed at sign-out. The Dashboard's closed only when the Dashboard unmounted. Each could outlive the session that opened it, keeping the scope the server fixed for that session, and a later sign-in reused it instead of opening its own. Payloads on these sockets are thin triggers that clients refetch over access-controlled REST (#918), which limits what could cross. Still, the socket's scope belonged to the wrong principal. Both now close when the session ends and reopen with a fresh ticket for the next one.

Decisions (the operator's, taken at claim time)

Changes

  • src/frontend/src/utils/platformSession.js: adds loginLocation and fullPathForVerdict. The reaction now passes goToLogin the location to push.
  • src/frontend/src/main.js: wiring only. Adds returnPath; goToLogin becomes (location) => router.push(location).
  • src/frontend/src/router/index.js: a logged-out deep link gets loginLocation(to.fullPath); a signed-in /login goes through landingAfterSignIn(to.query.redirect, …).
  • src/frontend/src/views/Portal.vue: adds the sign-in card's platform-login line, a router-link styled with HELP_CLASS and action-primary tokens. No raw palette classes.
  • src/frontend/src/App.vue, src/frontend/src/utils/websocket.js: the app-wide socket follows authStore.token (followToken). ws is now a shallowRef, so the per-socket identity check can match.
  • src/frontend/src/views/Dashboard.vue, src/frontend/src/stores/network.js: the Dashboard's own socket follows the token too (networkStore.followToken), with the same guards.
  • src/frontend/src/utils/socketSession.js: socketActionFor, the one rule both sockets follow. It is a leaf module because utils/websocket.js imports the network store.
  • Docs and comments:

Test plan

  • New specs, written first and seen red:
    • loginReturnPath.spec.js uses the app's real router and guard and the real Login.vue. Pinned there:
    • workspacePoll401.mount.spec.js runs the Workspace poll through the real portalHttp interceptors, with the handler composed as main.js composes it.
      • A token that is dead on the server goes to /login?redirect=.
      • A session ended in another tab stays on the card, and the poll that then goes out with no credential is not reported.
    • workspacePlatformLogin.mount.spec.js mounts Portal.vue:
      • the link's copy and target (the Workspace page, or the shared canvas);
      • the link shows on both steps;
      • the link is hidden while a platform session is held.
    • appSocketFollowsToken.mount.spec.js mounts App.vue with the real auth store:
      • a client-side login connects;
      • a new token reconnects, with a fresh ticket and no replay cursor;
      • a logout, or a sign-out elsewhere, disconnects with no reconnect after it;
      • a late open, message or close from a socket already let go of touches nothing;
      • two connects while a ticket mints open one socket, and a retry scheduled in an ended session never runs in the next one;
      • a dropped connection and the 4000 rescope still reconnect;
      • an auth rejection (4001) does not reconnect.
    • dashboardSocketFollowsToken.mount.spec.js mounts Dashboard.vue. Its own socket:
      • closes on a sign-out, here or in another tab, and nothing reopens it;
      • reconnects for the next session with a fresh ticket and no replay cursor, including when the token changes while the first ticket is minted;
      • ignores late events from the socket it replaced;
      • opens one socket at a time;
      • still closes when the Dashboard unmounts.
    • platformSessionSync.spec.js gains the main.js wiring pin.
  • Mutation battery: 30 mutations, each one turning a test red:
    • a bare /login in the guard, in the reaction, and in main.js;
    • the signed-in /login guard dropping the redirect;
    • the link's gate, target, and presence;
    • removing the token watch;
    • a disconnect that isn't deliberate;
    • removing the per-socket identity check;
    • keeping the replay cursor;
    • a late ticket opening a socket;
    • reconnecting on 4001;
    • not reporting the Workspace's 401;
    • each guard on the Dashboard's socket (identity checks on open, message, error and close; the generation; the mint and connecting dedupe; the token recorded at mint start; the cursor reset) and its watch in Dashboard.vue.
  • Full host vitest run: 6501 passed. The only reds are host-environment ones unrelated to this diff: @vue/compiler-sfc is not installed for 3 specs, and the host's newer DOMPurify trips markdownCodeBlocks. The raw-color, loading-gate and source-text ratchets pass, and so do check:tokens and vite build.
  • Eyeballed on a local instance at 1440 and 768, in light and dark:
  • The dead session was produced by revoking the token on the server, in a single tab, not by editing browser storage. A storage edit leaves the in-memory and stored credentials disagreeing. With a sibling tab open, it is that tab which ends the session, which is the bug(session): main app and Workspace disagree about the platform session — two credential sources, no cross-tab sync, three 401 logout paths; a stale Workspace tab logs a fresh re-login out #2791 path and by design does not navigate.
  • /review and /validate-pr ran on this PR. /review found no critical issues and two informational ones: the Dashboard socket, and six socket guards no test pinned. Both are fixed in 6351fdacc.
  • CI green (frontend-e2e runs via the ui label).

No backend, migration, requirements or docker/ change.

Overlap: draft #2709 already conflicts with dev in utils/websocket.js (its handleMessage branch). This PR does not touch that hunk; whichever PR lands second rebases.

Fixes #3444, Fixes #3445, Fixes #3466

Reviewer: @dolho, who owns epic #3471 and wrote the single 401 handler (#2811).

🤖 Generated with Claude Code

webmixgamer and others added 2 commits October 28, 2026 17:33
… follows the session (#3444, #3445, #3466)

Found in the UI sweep. Three symptoms, one gap: nothing on the way to /login
said where the person had been, and nothing tied the real-time socket to the
platform session.

#3444 — the login return path
- utils/platformSession.js: loginLocation(returnPath) builds the one way to
  /login, with ?redirect= for any in-app page (none for /, the sign-in pages,
  or anything safeRedirect refuses). fullPathForVerdict reads the page a 401
  happened on, query and hash included, from the address bar until the router
  settles (the #3406 rule).
- router/index.js: a logged-out deep link goes to loginLocation(to.fullPath);
  a signed-in visit to /login?redirect=X lands on X through landingAfterSignIn
  instead of /.
- reactToPlatformUnauthorized hands goToLogin loginLocation(returnPath), so a
  session that dies mid-use comes back to its page. main.js only wires it.
  #2791's verdict ordering is unchanged; the public token pages (#3406) still
  never navigate.

#3466 — an operator whose session ends in the Workspace
- The logout verdict above covers a dead token on the Workspace too.
- Portal.vue: the sign-in card gains "Have a Trinity account? Sign in" under
  both steps, to /login?redirect=<this page> (or the shared canvas the visitor
  came from), shown only while no platform session is held. No automatic
  navigation for a sign-out in another tab (#2791's rule stands).

#3445 — the header connection indicator after a client-side login
- App.vue watches authStore.token instead of connecting once on mount:
  connect when a token appears, reconnect when it changes, disconnect when it
  goes. The decision is the pure socketActionFor.
- utils/websocket.js: disconnect() is deliberate (a generation counter
  cancels the 5 s retry and a ticket still being minted; the replay cursor is
  dropped), each socket's handlers answer for that socket only, and the socket
  lives in a shallowRef so that identity check can match. A dropped
  connection and the 4000 rescope still reconnect; 4001 still does not.
- The same root cause left the previous session's socket open after a
  sign-out, still carrying the scope fixed for it at connect; it now closes.

Tests: loginReturnPath.spec.js (the real router and Login.vue, with #3406's
visitor path pinned beside it), workspacePlatformLogin.mount.spec.js,
appSocketFollowsToken.mount.spec.js, and a main.js wiring pin in
platformSessionSync.spec.js. Docs: workspace-session-signout flow, workspace
and frontend architecture notes, two stale comments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sport (#3466)

A Workspace tab left open when the platform token dies on the server: the
next poll 401s on the stored token, the one handler judges it `logout`, and
the tab goes to /login?redirect=<the Workspace page>. When the session ends
in another tab instead, this tab hears `storage` and by #2791's rule does not
navigate; its next poll carries no credential, is not reported, and the card
offers the platform login with the same return path.

Driven through real axios instances with a fake adapter, the interceptors the
modules register, the handler composed as main.js composes it, the app router
and Portal.vue mounted on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@webmixgamer webmixgamer added the ui PR touches the frontend UI — triggers Playwright e2e tests label Oct 28, 2026
@webmixgamer
webmixgamer requested a review from dolho October 28, 2026 18:33
…cket guard is pinned (#3445)

Two findings from the /review of this PR.

The SPA holds two /ws connections. The first commit made the app-wide one
(utils/websocket.js) follow the platform token. The Dashboard opens its own
(stores/network.js, opened on mount, closed on unmount) and read the token
only when it connected. A Dashboard left mounted across a session that ended
in another tab kept the earlier session's socket, including after someone
else signed in. Dashboard.vue now watches authStore.token and hands it to
networkStore.followToken. Both sockets decide with one pure rule,
utils/socketSession.js::socketActionFor, a leaf module because
utils/websocket.js imports the network store. The Dashboard socket gets the
same guards as the app-wide one:
- a generation that drops a ticket minted for an ended session;
- one ticket and one socket at a time;
- handlers that act only for their own socket (shallowRef, so the identity
  check can match);
- the replay cursor dropped when a new session starts.

Six of the app-wide socket's guards could be deleted with the suite still
green. The open and message identity checks and the concurrent-mint dedupe
now have tests, and so does the retry cancelled by a sign-out. Two checks
were redundant with a twin and are removed: the post-mint ws.value check and
the retry timer's generation check. A mutation battery over both sockets and
their wiring (21 mutations) turns a test red for each one.

User docs (Workspace sign-in, FAQ) now say where a sign-in returns you and
what the Workspace card offers. The flow doc, frontend.md and a
Recent Updates row follow. A learnings fragment records the two-socket class.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@dolho dolho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/review: no critical issues, approving

Execution coverage. The 6 new or changed specs pass (105 tests), and CI build (npm run test:unit) plus e2e are green. I ran my own mutation check on top of the PR's: each of these turned a test red.

  • a bare /login on a 401;
  • a bare /login in the router guard;
  • a signed-in /login?redirect= that drops the redirect;
  • the app socket's onclose without its identity check;
  • a disconnect() that leaves the retry timer running;
  • a late ticket opening the Dashboard socket;
  • a late ticket opening the app socket;
  • the gate on the Portal sign-in link.

The source-text pin on main.js sits in the existing wiring-only block. That is a reasonable guard, since main.js mounts the app on import. Every return path goes through safeRedirect, so I see no open-redirect risk.

Informational, not blocking:

I1. A socket can be marked as opened for a token when no socket was opened.

  • utils/websocket.js: followToken sets socketToken = token before connect(), but connect() reads readStoredToken() and returns early when storage is empty. The state then says "open for this token" with no socket, and the next followToken(sameToken) returns none. It is safe today only because _finalizeLogin (stores/auth.js) writes localStorage synchronously before the watcher flushes. Passing the token into connect(), or recording it only once a socket exists, would remove that dependency on ordering.
  • stores/network.js: when the ticket mint fails, connectWebSocket returns with socketToken already set and never retries, so the Dashboard socket stays down until the token changes or the Dashboard remounts. No retry was the old behaviour too, but the new state now hides it.

Low confidence / nits

  • loginLocation drops the redirect for / with a query (/?view=list comes back as bare /).
  • followToken resets the replay cursor on any token change, including a same-user token refresh (the password-change path in stores/auth.js), so a short gap of events may not be replayed. Probably acceptable.

🤖 Generated with Claude Code

webmixgamer and others added 2 commits October 29, 2026 14:35
…y; a dashboard link keeps its query through sign-in (#3444, #3445)

Three informational points from the PR review.

- utils/websocket.js: followToken recorded the token before connect() had
  checked storage. A token whose socket could not start (nothing stored yet)
  therefore read as "open for this token", and the next call for it did
  nothing. It was safe only because sign-in writes storage before the watch
  runs. connect() now records the token once a ticket is being minted, the
  way the Dashboard socket already does.
- stores/network.js: a failed ticket mint left the token recorded, so the
  state said a socket was open for it when none was. It now clears. There is
  still no retry; that was already the behaviour.
- loginLocation dropped the return path for any dashboard URL. Now only the
  bare "/" does: a dashboard link with a query (?view=, ?tags=) is a
  destination and keeps it through sign-in.

Each change has a test that was red before it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolves the one conflict, docs/memory/feature-flows.md Recent Updates: both
2026-10-28 rows kept (this PR's, then ent#1006's).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@webmixgamer

Copy link
Copy Markdown
Contributor Author

@dolho thanks. All four addressed:

  • I1a (app socket): fixed in a3411f8. connect() now records the token once a ticket is being minted, the way the Dashboard socket does, and followToken no longer records it. Test: a token whose socket could not start yet (nothing stored) is not recorded, so the next call connects.
  • I1b (Dashboard socket): fixed in a3411f8. A failed mint now clears the recorded token. There is still no retry, as before.
  • /?view=list: fixed in a3411f8. Only the bare / drops the return path now; a dashboard link with a query keeps it through sign-in (tested through the real router and Login.vue).
  • Cursor reset on a same-user token refresh: left as is. It happens only on a password change, the gap is a few seconds, and dropping the cursor is the safe direction.

Since your review I also merged dev (82a1e02). The only conflict was the Recent Updates row in docs/memory/feature-flows.md, and both rows are kept. CI is green on that head.

@webmixgamer
webmixgamer merged commit d2d5cd8 into dev Oct 30, 2026
25 checks passed
@webmixgamer
webmixgamer deleted the feature/3444-login-return-path branch October 30, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants