import type { SessionRecord } from "../../db"; import { escapeHtml } from "./html"; type SessionsMessage = { text: string; type?: "success" | "error"; }; function summarizeUserAgent(userAgent: string | null): string { if (!userAgent) return "Unknown"; return userAgent.length > 80 ? `${userAgent.slice(0, 77)}...` : userAgent; } function renderMessage(message?: SessionsMessage): string { if (!message) return ""; const classes = message.type === "error" ? "text-rose-200 border-rose-700 bg-rose-900/30" : "text-emerald-200 border-emerald-700 bg-emerald-900/30"; return `
${escapeHtml(message.text)}
`; } function renderSessionRow( session: SessionRecord, currentTokenHash: string | null, now: number, ): string { const current = session.tokenHash === currentTokenHash; const expired = session.expiresAt <= now; const canRevoke = !session.revoked && !expired; const status = session.revoked ? 'Revoked' : expired ? 'Expired' : 'Active'; const currentBadge = current ? ' Current' : ""; const confirmation = current ? "This will revoke your current session and log you out. Continue?" : "Revoke this session?"; return `View and manage your active login sessions.
| IP | Browser / Client | Created | Last Active | Status | Action |
|---|