Skip to content

feat(auth): implement session management for user devices - #789

Merged
pikann merged 5 commits into
masterfrom
feature/implement-session-management-feature
Nov 19, 2026
Merged

pikann merged 5 commits into
masterfrom
feature/implement-session-management-feature

Conversation

@pikann

@pikann pikann commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Lets users see the browsers/devices their account is signed in on and sign any of them out (Account → Security → "Signed-in devices").

Login was stateless (JWTs plus a Redis refresh-token family per login) and nothing listed those families. Each family is now a session, tracked in a Redis registry.

Backend

  • Session registry — SessionStore interface (domain/auth) with a Redis implementation (session:{familyId} hash + per-user sorted index, both expiring with the refresh token). No DB migration. Stores IP, User-Agent, created time and last-active time.
  • Lifecycle — a session is recorded at login (password, MFA, passkey and SSO; IssueSession now takes a ctx to read client info), touched on every refresh (sessions that predate this change are adopted on their next refresh), and removed on logout.
  • Remote sign-out is immediate — revoking a family previously only blocked refresh, so a signed-out device kept working until its access token expired (15 min by default). Authn now also rejects access tokens whose family is revoked, via Manager.WithRevocationCheck. This adds one Redis lookup per authenticated request. If the lookup errors it fails open, so a Redis outage does not sign everyone out; refresh still fails closed.
  • API (JWT/cookie auth only, API keys rejected; always scoped to the caller's own sessions):
    • GET /users/me/sessions
    • DELETE /users/me/sessions/{sessionId}
    • DELETE /users/me/sessions (all but the current one)
    • A session id that is not yours returns 404 SESSION_NOT_FOUND, same as an unknown one.
  • Browser/OS are parsed from the User-Agent by a small built-in parser; unrecognised clients show as "Unknown device".

Web

  • SessionsCard on the security page: device name, IP, last active, sign-in date; current device is badged and has no sign-out button (use normal logout). Per-device and "sign out all other devices" actions both confirm first.
  • New strings translated in all 9 locales.

Notes

  • "Last active" only advances when the access token rotates, so it can lag by up to ~15 minutes.
  • Not changed: password change / admin reset do not sign out other sessions. Possible follow-up.

Testing

  • Go unit tests: Redis store (miniredis), service (record / list / revoke / revoke-others / logout / refresh), handler, Authn revocation (including fail-open), User-Agent parser, route coverage.
  • Web: SessionsCard tests, tsc -b, biome, locale parity test.
  • Not yet run: against a real Redis stack or the e2e suite.

- Add SessionStore interface and Redis implementation for session management.
- Introduce session handling in auth service, including session creation, listing, and revocation.
- Implement HTTP handlers for session management, allowing users to view and manage their active sessions.
- Enhance authentication middleware to check for revoked sessions.
- Add tests for session management functionality, ensuring proper behavior for session creation, revocation, and listing.

@pullfrog pullfrog Bot 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.

Important

The registry is the only input to "sign out all other devices", and one token-rotation path never writes it, so some live sessions are invisible in the UI and cannot be ended from it.

Approach: sound — sessions ride the existing refresh-token family, so revocation reuses one token lifecycle and one Authn chokepoint instead of introducing a second identity concept.

Reviewed changes

Read the full diff for 3ab10b8 (34 files): the Redis registry and session lifecycle, the access-token revocation check, the three self-service routes and handler, the web card with its locales, and the tests.

  • Session registry — one hash per family plus a per-user sorted index scored by last activity, both expiring with the refresh token and pruning entries whose hash already expired.
  • Lifecycle wiring — sessions recorded at password, MFA, passkey and SSO login, touched on refresh with adoption of pre-registry sessions, and forgotten on logout.
  • Immediate revocation — Authn now rejects an access token whose family was signed out (fail-open on lookup errors), closing the up-to-15-minute window.
  • Self-service API — list, revoke one, and revoke all others, JWT-only and scoped to the caller's account with a uniform 404 for unknown or foreign ids.
  • Web — SessionsCard with per-device and bulk sign-out behind confirmation, translated in all nine locales.
  • Tests — miniredis store tests, service and handler coverage, authn revocation including fail-open, the User-Agent parser, route coverage, and the card's component tests.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

Reviewed the delta from 3ab10b8 to 48c4090 (5 files), which addresses all four findings from the previous review.

  • Index expiry is now atomic — the TTL read and conditional PEXPIRE run in one Lua script inside the save transaction, so concurrent saves with different TTLs can only extend the per-user index.
  • Non-UUID session ids are rejected — Get/Delete treat malformed ids as not-found, so DELETE /users/me/sessions/{sessionId} returns the documented 404 instead of a WRONGTYPE 500.
  • Annotation refresh keeps the registry current — RefreshAnnotation now calls recordSession, so a family kept alive only by the extension stays listed and revocable.
  • Stale revoke error cleared — the dialog's onSuccess resets failed before closing.
  • New tests — store coverage for non-UUID ids and non-shortening index expiry, plus a service test that annotation refresh re-registers a lapsed session.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

Reviewed the delta from 48c4090 to 180b147 (2 files), which adds Playwright coverage for the signed-in devices feature.

  • Feature specification — apps/e2e/features/auth/sessions.feature records the seven scenarios: listing, browser/system labels, logout removal, per-device sign-out, cancelling, sign-out all others, and cross-account/malformed-id 404s.
  • Browser coverage — apps/e2e/tests/auth/sessions.spec.ts drives each scenario with separate browser contexts and spoofed User-Agents, and verifies revocation with real API calls plus a reload-to-login check rather than UI state alone.
  • Isolation and conventions — throwaway users under a non-overlapping E2E_SESSIONS_ prefix, per-test cleanup, contexts closed in finally; helpers and selectors match the existing auth specs and the card's accessible names.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

ℹ️ No critical issues — one minor observation inline.

Reviewed changes

Reviewed the delta from 180b147 to 4c2b42a (7 files, +40/-10), a hardening pass over the session registry, revocation and client-info paths.

  • Sign-in origin is now write-once — the Redis session hash keeps the first ip and user_agent via HSetNX and records each refresh's address in a separate last_ip, so a session used from elsewhere cannot rewrite where it began.
  • Bulk sign-out is resilient — RevokeOtherSessions skips families that are already revoked, keeps revoking the rest when one RevokeFamily fails, and returns the combined error; the handler also refuses to run when the caller's token carries no family id.
  • Outage logging is throttled — a failing revocation lookup now warns at most once a minute instead of once per authenticated request.
  • User-Agent handling tightened — the Opera match requires Opera/, and oversized headers are truncated on a valid UTF-8 boundary.
  • Store test updated — asserts the sign-in IP survives a refresh and the new address lands in last_ip.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

Reviewed the delta from 4c2b42a to 176fab44 (3 files), which acts on the previous review's minor observation about the unused last_ip field.

  • LastIP removed end to end — the domain field, the last_ip hash write in Save, its decode in decodeSession, and the store-test assertion are gone, so the session hash now carries only fields something reads.
  • Sign-in origin still write-once — ip and user_agent remain HSetNX and last_active_at is the only field rewritten on a refresh; the store test still asserts a refresh from a new address cannot overwrite the recorded sign-in address.
  • No stragglers — nothing in the repo references LastIP/last_ip any more, and unknown hash fields are ignored on read, so hashes written by 4c2b42a stay readable.

gofmt, go vet and the domain/auth, repository/redis and service/auth test packages are clean at 176fab44.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann
pikann merged commit dc4a8a0 into master Nov 19, 2026
8 checks passed
@pikann
pikann deleted the feature/implement-session-management-feature branch November 19, 2026 11:22
robertcoroianu added a commit to robertcoroianu/paca that referenced this pull request Nov 19, 2026
Secondary text and hairlines were faded well past readability. The base
tokens were fine on their own (muted text 4.7:1 on white), but
components layered heavy opacity on top: ~380 uses of muted text at
/30-/60 rendered at roughly 1.5-2.3:1, and borders at /10-/30 were
close to invisible (1.04-1.12:1).

Tokens (index.css):
- --muted-foreground: #737373 -> #5f5f5f (light, 6.4:1),
  #888888 -> #a0a0a0 (dark, 7.6:1)
- --border/--input: #d4d4d4 -> #c8c8c8 (light), #2a2a2a -> #3a3a3a (dark)
- --sidebar-border: #e8e8e8 -> #dedede (light), #1e1e1e -> #2a2a2a (dark)

Opacity floors across components (mechanical sweep):
- text-muted-foreground /30-/60 -> /90 (>= 4.5:1 on background, muted
  and secondary surfaces in both themes; /85 would still fail at
  4.48:1), /70-/90 -> full strength, so two tiers remain
- text-sidebar-foreground /30-/50 -> /60 (4.94:1 light, 6.53:1 dark);
  the sidebar has its own foreground token
- border/divide/ring/bg-border /10-/35 -> /50, /40 -> /60; Gantt
  gridlines /12 -> /30 so they stay lighter than row dividers. The
  dashed row dividers from Paca-AI#785 are left as tuned.

The Gantt drag tests located groups by a border class; they now use a
`data-gantt-group` attribute so styling changes don't break them.

Rebuilt on current master (after Paca-AI#784, Paca-AI#785-Paca-AI#787, Paca-AI#789) so the new
file-management components get the same treatment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant