From 713b494f046543ec688a38e628044bae9e4d00f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 10 May 2026 13:57:04 +0200 Subject: [PATCH] fix(admin): humanise auto-issued token names in viewer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The native auto-login flow names tokens by suffixing the issuing call's `Date.now().toISOString()`, so the admin viewer rendered "iOS auto-login 2026-05-05T19:46:20.603Z" — readable as debug output, not as something a person picked. Added a renderer-side formatter that detects the trailing ISO timestamp and rewrites the cell to "iOS auto-login · 05.05.2026 19:46". Manual token names without an ISO suffix pass through unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../admin/api-token-overview-section.tsx | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/components/admin/api-token-overview-section.tsx b/src/components/admin/api-token-overview-section.tsx index 31b8bd924..c32e67644 100644 --- a/src/components/admin/api-token-overview-section.tsx +++ b/src/components/admin/api-token-overview-section.tsx @@ -58,6 +58,32 @@ function TruncatedCell({ ); } +/** + * F-18 (v1.4.19): the auto-login flow names tokens + * "web auto-login 2026-05-05T19:46:20.603Z" / "iOS auto-login …" by + * suffixing the issuing call's `Date.now().toISOString()`. That suffix + * makes the admin list look like debug output. Reformat to + * "iOS auto-login · 05.05.2026 19:46" while leaving any non-ISO suffix + * (manual names, device fingerprints, etc.) untouched. + */ +const TOKEN_NAME_ISO_RE = + /^(.+?)\s+(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z)(.*)$/; + +function formatTokenName(name: string): string { + const match = TOKEN_NAME_ISO_RE.exec(name); + if (!match) return name; + const [, prefix, iso, rest] = match; + const d = new Date(iso); + if (Number.isNaN(d.getTime())) return name; + const dd = String(d.getUTCDate()).padStart(2, "0"); + const mm = String(d.getUTCMonth() + 1).padStart(2, "0"); + const yyyy = d.getUTCFullYear(); + const hh = String(d.getUTCHours()).padStart(2, "0"); + const mi = String(d.getUTCMinutes()).padStart(2, "0"); + const formatted = `${prefix} · ${dd}.${mm}.${yyyy} ${hh}:${mi}`; + return rest && rest.trim() ? `${formatted} ${rest.trim()}` : formatted; +} + export function ApiTokenOverviewSection() { const { t } = useTranslations(); // v1.4.19 phase A7 — `/admin/api-tokens` is a dedicated single- @@ -153,7 +179,7 @@ export function ApiTokenOverviewSection() { - +
@@ -223,7 +249,7 @@ export function ApiTokenOverviewSection() {
{token.revoked ? (