C.W.K.
Stream
Lesson 03 of 05 · published

Active Sessions Table — Who Is Logged In Right Now

~15 min · sessions-table, ip-annotation, ux

Level 0Greenhorn
0 XP0/53 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

This is the table you'll look at most. It answers "what's actually authenticated against my app right now, from where, since when, and for how much longer?"

What to show per row

ColumnWhyDisplay tip
Token prefix (8 chars)Lets you correlate with audit log without exposing full tokenUse monospace
IPTells you which device this isAnnotate known IPs ("My Laptop", "Phone (Tailscale)")
Created atHow long ago the login happenedRelative ("3 hours ago") + tooltip with absolute
Expires at / time leftWhen it'll auto-dieColor: red if <30min, gray otherwise
"Revoke" buttonSurgical killInline, requires confirm

Sorting and filtering

Don't add a sort/filter framework. Solo apps rarely have more than 5 active sessions. Sort by created_at desc and stop. If you ever have 50, you have a different problem worth investigating manually.

Code

Active sessions query·sql
SELECT
  substr(token, 1, 8) || '…' AS token_prefix,
  ip,
  created_at,
  expires_at,
  (expires_at - strftime('%s','now')) / 60 AS minutes_remaining
FROM security_sessions
ORDER BY created_at DESC;
Annotate known IPs with friendly names·python
KNOWN_IPS = {
    "100.64.0.5":  "Phone (Tailscale)",
    "100.64.0.10": "Laptop (Tailscale)",
    "100.64.0.15": "Tablet (Tailscale)",
    "192.168.1.50": "Desktop (LAN)",
    "127.0.0.1":   "Local",
}

def label_ip(ip: str) -> str:
    return KNOWN_IPS.get(ip, ip)

External links

Exercise

Render the active sessions query as an HTML table with the IP labelling. Login from your laptop, phone, and a tablet (or three browsers). Verify each row picks up the right friendly name. Add a 'Revoke' button per row that hits /admin/security/sessions/{prefix}/delete from Track 7.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.