import { generateSecret, generateURI } from "otplib"; import QRCode from "qrcode"; import { sql } from "@/db"; import { requireUserPage } from "@/lib/auth/guard"; import { csrfToken } from "@/lib/auth/session"; import { accountAction } from "@/lib/admin/actions"; import { Csrf, Field, Notice, PageTitle } from "@/components/admin-ui"; export default async function Account({ searchParams }: { searchParams: Promise> }) { const sp = await searchParams; const u = await requireUserPage(); const csrf = csrfToken(u); const sessions = await sql`SELECT id, ip, user_agent, created_at, last_seen_at FROM sessions WHERE user_id = ${u.id} AND revoked_at IS NULL AND expires_at > now() ORDER BY last_seen_at DESC`; const secret = u.totpEnabled ? null : generateSecret(); const qr = secret ? await QRCode.toDataURL(generateURI({ issuer: "wp.spboucher.ai", label: u.email, secret })) : null; return (
{sp.must_change &&

You must change the initial password before using the administration.

}

Change password

Two-factor authentication (TOTP)

{u.totpEnabled ?

Enabled.

:

Scan with an authenticator app, then enter the 6-digit code.

{qr && TOTP QR code}

{secret}

}

Active sessions

{sessions.map((s) => )}
IPClientCreatedLast seen
{s.ip}{s.id === u.sessionId ? " (this)" : ""}{s.user_agent}{new Date(s.created_at).toLocaleString("en-CA")}{new Date(s.last_seen_at).toLocaleString("en-CA")}
); }