Repository navigation
fix(ui): sign-in returns to the page you were on, and the live socket follows the session (#3444, #3445, #3466) - #4069
Conversation
… 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]>
…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
left a comment
There was a problem hiding this comment.
/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
/loginon a 401; - a bare
/loginin the router guard; - a signed-in
/login?redirect=that drops the redirect; - the app socket's
onclosewithout 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:followTokensetssocketToken = tokenbeforeconnect(), butconnect()readsreadStoredToken()and returns early when storage is empty. The state then says "open for this token" with no socket, and the nextfollowToken(sameToken)returnsnone. It is safe today only because_finalizeLogin(stores/auth.js) writeslocalStoragesynchronously before the watcher flushes. Passing the token intoconnect(), or recording it only once a socket exists, would remove that dependency on ordering.stores/network.js: when the ticket mint fails,connectWebSocketreturns withsocketTokenalready 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
loginLocationdrops the redirect for/with a query (/?view=listcomes back as bare/).followTokenresets the replay cursor on any token change, including a same-user token refresh (the password-change path instores/auth.js), so a short gap of events may not be replayed. Probably acceptable.
🤖 Generated with Claude Code
…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]>
|
@dolho thanks. All four addressed:
Since your review I also merged |
Summary
Three symptoms found in the UI sweep (epic #3471, PR 6) share one gap: nothing on the way to
/loginsaid where the person had been, and nothing tied the real-time sockets to the platform session./login, even thoughLogin.vuehas honoured?redirect=since bug: returning visitors of email-verified public chat links are sent to the operator /login after 24 h and stay locked out #3406. Both now build the location with one pure function,loginLocation(returnPath)inutils/platformSession.js. A signed-in visit to/login?redirect=Xnow lands on X (throughlandingAfterSignIn) instead of/./login?redirect=<the Workspace page>. This is the same 401 reaction, with no Workspace-specific code. If the session ends in another tab, the Workspace tab still does not navigate (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's rule, kept by decision). Instead, the sign-in card shows "Have a Trinity account? Sign in" under both steps. It links to/login?redirect=<this page>, or to the shared canvas the visitor came from, and appears only while no platform session is held.App.vueopened the app-wide socket once, on mount, and only if a token was already stored. It now watches the auth token: it connects when a token appears, reconnects when it changes, and disconnects when it goes. The Dashboard's own socket (stores/network.js) follows the same rule fromDashboard.vue. Both decide with one pure function,socketActionForinutils/socketSession.js. A disconnect is now deliberate: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
/wsconnections, 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)
SharedCanvas.vuealready ships. The card's heading and subline are unchanged./logingets no new line for a link arrival; that block belongs to fix(workspace): portal-minted sign-in codes also redeem at the platform login #3983.Login.vueis not touched./login. fix(session): one platform credential, one 401 verdict, one handler (#2791) #2811's one-verdict ordering and bug(frontend): after a deploy, a stale tab loops POST /api/auth/logout → 401 (~20–50 req/s) and signs every fresh login out #2852's 401 path are unchanged.Changes
src/frontend/src/utils/platformSession.js: addsloginLocationandfullPathForVerdict. The reaction now passesgoToLoginthe location to push.src/frontend/src/main.js: wiring only. AddsreturnPath;goToLoginbecomes(location) => router.push(location).src/frontend/src/router/index.js: a logged-out deep link getsloginLocation(to.fullPath); a signed-in/logingoes throughlandingAfterSignIn(to.query.redirect, …).src/frontend/src/views/Portal.vue: adds the sign-in card's platform-login line, arouter-linkstyled withHELP_CLASSandaction-primarytokens. No raw palette classes.src/frontend/src/App.vue,src/frontend/src/utils/websocket.js: the app-wide socket followsauthStore.token(followToken).wsis now ashallowRef, 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 becauseutils/websocket.jsimports the network store.stores/clientPortal.jsanddocs/memory/architecture/workspace.mdhad stale notes saying@/api's 401 hard-navigates. It hasn't since 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; both are corrected.architecture/frontend.md, in theworkspace-session-signout,workspace-only-roleandadmin-loginfeature flows, and in a Recent Updates row.sharing-and-access/workspace.md(Signing in and out),faq/security.mdandfaq/troubleshooting.mdsay where a sign-in returns you and what the Workspace card offers.ref()proxy breaks socket identity, and the SPA's two/wsclients.Test plan
loginReturnPath.spec.jsuses the app's real router and guard and the realLogin.vue. Pinned there:/login?redirect=<fullPath>;/login?redirect=Xlands on X;/chat/:tokenand/canvas/s/:tokennever navigate.workspacePoll401.mount.spec.jsruns the Workspace poll through the realportalHttpinterceptors, with the handler composed asmain.jscomposes it./login?redirect=.workspacePlatformLogin.mount.spec.jsmountsPortal.vue:appSocketFollowsToken.mount.spec.jsmountsApp.vuewith the real auth store:dashboardSocketFollowsToken.mount.spec.jsmountsDashboard.vue. Its own socket:platformSessionSync.spec.jsgains themain.jswiring pin./loginin the guard, in the reaction, and inmain.js;/loginguard dropping the redirect;Dashboard.vue.vitest run: 6501 passed. The only reds are host-environment ones unrelated to this diff:@vue/compiler-sfcis not installed for 3 specs, and the host's newer DOMPurify tripsmarkdownCodeBlocks. The raw-color, loading-gate and source-text ratchets pass, and so docheck:tokensandvite build./login?redirect=;/reviewand/validate-prran on this PR./reviewfound no critical issues and two informational ones: the Dashboard socket, and six socket guards no test pinned. Both are fixed in6351fdacc.frontend-e2eruns via theuilabel).No backend, migration, requirements or
docker/change.Overlap: draft #2709 already conflicts with
devinutils/websocket.js(itshandleMessagebranch). 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