Skip to content

port: feat: add session management page (list active sessions + revoke) (upstream #4841)#164

Merged
AminDhouib merged 2 commits into
canaryfrom
port/upr-4841
Jul 18, 2026
Merged

port: feat: add session management page (list active sessions + revoke) (upstream #4841)#164
AminDhouib merged 2 commits into
canaryfrom
port/upr-4841

Conversation

@AminDhouib

Copy link
Copy Markdown
Member

Ports upstream Dokploy/dokploy#4841 by @daniloneto into the fork.

Summary

Adds a Settings → Sessions page listing the signed-in user's active and expired login sessions with IP address, device (parsed from user-agent), and timestamps, plus a revoke (force logout) action for every session except the current one. Navigation entry lives under Users (gated by member.read, matching upstream's placement).

Security adaptation (fork divergence)

The task's security requirement is that these endpoints only ever touch the current user's own sessions. Upstream exposes them as admin endpoints over all users' sessions, so they were adapted:

Upstream Dokploy#4841 This fork port
listSessions adminProcedure, all users' sessions protectedProcedure, where userId = ctx.user.id only
revokeSession adminProcedure, any session (self blocked) protectedProcedure, deletes only after targetSession.userId === ctx.user.id; self-revocation blocked
Not-owned session n/a reported as NOT_FOUND (never confirms another user's session exists)
Session token not selected not selected (metadata only: IP, UA, createdAt, expiresAt, current marker)

isCurrent is computed in JS (s.id === ctx.session.id) rather than as a SQL eq(...) expression, so the tRPC return type stays a plain boolean (drizzle typed the SQL expression as unknown). Works with the fork's better-auth 1.6.23 + 30-day sessions — the page reads real session rows and revocation deletes the row.

The frontend component, page, sidebar entry, and validation test are applied verbatim from upstream.

Verification

  • pnpm --filter=dokploy typecheck — clean.
  • pnpm exec vitest __test__/api/session-management.test.ts --run3 passed.

Credit: @daniloneto (upstream Dokploy#4841).

daniloneto and others added 2 commits July 18, 2026 01:35
Add a Settings > Sessions page listing the current user's active and
expired login sessions with IP address, device, and timestamps, plus a
revoke (force logout) action for any session other than the current one.

Backend (apps/dokploy/server/api/routers/user.ts):
- listSessions: returns the caller's own sessions joined with user data,
  ordered by creation date (metadata only; the session token is never
  selected or returned)
- revokeSession: deletes a session by id after verifying the caller owns
  it, and blocks self-revocation of the current session

Ported from upstream Dokploy#4841. Adapted for the fork: upstream
exposed these as admin endpoints over ALL users' sessions; here both are
protectedProcedures strictly scoped to the caller's own sessions, and a
session owned by another user is reported as NOT_FOUND so the endpoint
never confirms its existence. isCurrent is computed in JS to keep the
tRPC return type a plain boolean.
@AminDhouib
AminDhouib merged commit ae07249 into canary Jul 18, 2026
3 checks passed
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.

2 participants