Skip to content

[P6.7.1] Add proactive auth guard + SSE/WS token-expiry re-auth path #651

Description

@frankbria

Problem

The web UI has no proactive auth guard. The only auth gate is a reactive axios interceptor that redirects to /login after an API call returns 401. Consequences:

  • An unauthenticated visitor to /, /tasks, etc. renders the full sidebar + loading skeletons, then flickers to /login only after the first 401.
  • /login has no "already authenticated → redirect to /" check.
  • Token expiry mid-session on SSE/WebSocket streams (which auth via ?token=) silently fails into the hook's error state ("Connection failed") with no path back to re-auth — the reactive interceptor only fires on axios calls, not on EventSource/WebSocket.

Evidence

  • web-ui/src/lib/api.ts:147-152 — sole auth gate (reactive 401 → clear token → redirect)
  • web-ui/src/app/login/page.tsx — no already-authenticated redirect
  • useStressTestStream, useAgentChat, useTerminalSocket?token= auth, no re-auth on expiry

Fix

  • Add a lightweight route guard (in AppLayout or middleware) that redirects unauthenticated users to /login before rendering the shell.
  • Redirect authenticated users away from /login.
  • On SSE/WS auth failure (401/handshake reject), clear the token and redirect to /login.

Acceptance criteria

  • Unauthenticated navigation to a protected page redirects to /login without shell flicker.
  • Authenticated user hitting /login is redirected to /.
  • SSE/WS token expiry surfaces a re-auth path.

Source: release-readiness audit 2026-06-13 (frontend agent).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-high-betaHigh priority - should fix before beta for best experiencephase-6.7Phase 6.7: Frontend/UX hardening (post-beta-tag)ux

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions