Skip to content

feat(platform): pick an API key's expiry date and show it in the table - #4495

Merged
yannickmonney merged 6 commits into
mainfrom
feat/api-key-expiry
Oct 8, 2026
Merged

yannickmonney merged 6 commits into
mainfrom
feat/api-key-expiry

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

First of three PRs for the API-key request: a key's expiry date can now be chosen and is shown in the table. Keys for members, teams, projects and the organization, and the project budget scope, follow in separate PRs stacked on this one.

Why

The Create API key dialog only offered 7, 30 or 90 days, a year, or never. You could not pick a date, and after creation the expiry appeared nowhere in the UI.

What changes

  • Expiration gains a Custom date option. It opens an Expiration date calendar where you can pick any day from tomorrow to one year out. That is the window Better Auth's api-key plugin accepts (1 to 365 days in whole days), so the key expires at the time of day it was created, on the chosen day.
  • Under the field, a line names the day the key will expire ("The key expires on November 6, 2026."). For Never it says the key works until it is revoked.
  • The keys table has a new Expires column. It shows the date, Never, or an Expired badge for a key that ran out while the list was open. The plugin deletes expired keys the next time it lists, so such a row does not linger.
  • @tale/ui DatePicker gains minDate/maxDate. Out-of-range days are disabled and their label reads "Not available" in the UI language instead of react-datepicker's built-in English. The trigger now receives id, aria-labelledby and aria-describedby; before this change it silently dropped them, so no visible label could name it.
  • Docs (EN/DE/FR) for API keys, the catalogs (en/de/fr) and manual box SET-F76 are updated.

Verification

  • Real browser on an isolated stack (seeded owner):
    • The 90-day preset stored exactly 90 days (apikey.expiresAt − createdAt = 90.000 d).
    • Custom date → 20 November stored 44 days and rendered 11/20/2026 in Expires.
    • The hint line and the calendar bounds render as described.
  • Unit tests:
    • @tale/ui date-picker: 22 tests.
    • API-keys feature: 51 tests, covering the dialog's default, Never, a custom day, bounds and the missing date; the Expires cell; the column; and the expiry helpers.
  • Other checks:
    • Platform and @tale/ui i18n suites.
    • Docs tests (685).
    • lint:links, lint:manual, check-guide on settings.md.
    • oxlint on the touched files.
    • tsc for the platform and @tale/ui.

Not in this PR

The docs screenshot settings-api-keys predates the new hint line. Its alt text and the fields it shows are still accurate. It is retaken in the follow-up PR, which reshapes this dialog with an owner picker.

DatePicker takes minDate/maxDate (days outside are disabled and read
"Not available" in the UI language) and forwards id, aria-labelledby
and aria-describedby to its trigger, which dropped them before.
The create dialog offered 7/30/90 days, a year or never, and the date a
key stopped working was shown nowhere. Expiration now adds Custom date,
a calendar bounded to tomorrow through a year from today (the api-key
plugin's window), and names the day the key expires under the field.
The keys table gets an Expires column: the date, Never, or Expired for a
key that ran out while the list was open.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

REQUEST CHANGES — reviewed head b88f305be12a92dc96bb8a89e5a1310b30e2e757 against 4e5a70b648e761393594f500e206da9f4f49d2b1, API-only, Part B then Part A. I did not implement this PR. The PR names no implementing agent (GitHub author: yannickmonney).

  1. DATA / CODE / UX-CLARITY — custom dates drift when the dialog stays open. api-key-create-dialog.tsx validates and computes expiresIn against the frozen openedAt, while the plugin starts the lifetime at creation. Open on Oct 7, choose Oct 8, submit on Oct 8: it still sends 86,400 seconds and expires Oct 9. Leave it open longer and a now-past date still passes validation. Refresh bounds and validate against the submission clock; ensure the persisted date matches the promised date. Add midnight-rollover and stale/past-choice regressions; current fixed-clock tests cannot catch this.
  2. DATA / CODE — calendar days and 24-hour durations differ across DST. expiry.ts counts local calendar days but sends days * 86_400. In Europe/Zurich, creation Oct 24 2026 at 00:30 plus two 24-hour days expires Oct 25 at 23:30 after the fall-back, although Oct 26 was selected. Conversely, a spring-forward near midnight can advance the expiry into the next day. The helper hint uses the same duration, so it can contradict the selected date. Define and implement the date/timezone contract consistently with server storage and plugin limits; add both DST boundaries and near-midnight cases. The PR's claim that the key expires at its creation time on the chosen day is not generally true.
  3. CICD / CODE — repair the introduced Knip failure and supply all seven terminal gates. Knip job 112906942016 exits 1 for unused export API_KEY_MAX_EXPIRY_DAYS at expiry.ts:15. Keep this internally used constant unexported, or provide a legitimate external consumer. CI ready (Checks) is failed. Unit and UI aggregate jobs never started: their annotations say “repeatedly failed to be acquired (5 attempts)”; these are NOT_RUN, not test/product failures. CI ready (E2E) and CI ready (Build) are absent in the complete exact-head check response and their workflow job inventories. Successful children do not substitute for required terminal gates. Restore complete exact-head proof through the existing CI owner/lane.

Part B dispositions: SECURITY: UNAVAILABLE for comprehensive expiry-enforcement proof, not an observed bypass. backend/rest/v1.ts authenticates via auth.api.getSession before mounting REST/MCP/model routes; backend/auth/auth.ts enables Better Auth API-key sessions. Enforcement therefore lives in the existing plugin, not this UI. Inspected v1.test.ts mocks getSession; new tests cover frontend helpers/display, not real expired-key refusal. Please provide source-bound real-plugin evidence just before/at/after expiry across authenticated doors, including existing null-expiry keys and direct invalid-lifetime creation. DATA/CODE: FAIL findings 1–2; null expiry is preserved by sending undefined and displaying Never, with no schema/migration change. No local execution was authorized.

Part A dispositions: A11Y: source assessment supports forwarded trigger id/name/description, named unavailable days, native buttons and clear-button focus return; real keyboard/assistive interaction remains NOT_RUN. LOCALE: PASS for changed-key and ICU argument parity in en/de/fr (the new date interpolation is {date} in all three; shared disabled-day labels also match); rendered localized states NOT_RUN. UX-CLARITY: FAIL date promises above; Never/Expired wording is clear. UI-RESPONSIVE: source uses hidden sm:table-cell for expiry and preserves name/actions on phones; rendered widths NOT_RUN and expiry is unavailable below sm. REL-MANUAL: NOT_RUN; new SET-F76 is a procedure, not an execution receipt. Additional note: ExpiresCell samples Date.now only on render; it does not schedule a transition when a listed key expires, and its test mounts an already-expired key. DOCS: updated EN/DE/FR text carries the same date guarantee affected by findings 1–2; screenshot refresh is explicitly deferred.

Exact-head aggregator Observed result Check ID
CI ready (Checks) FAIL 112909588871
CI ready (Commitlint) PASS 112907245634
CI ready (SAST) PASS 112908646046
CI ready (Security) PASS (conditional gate; scans skipped) 112907024897
CI ready (CLI) PASS (conditional gate; build skipped) 112907032567
CI ready (E2E) UNAVAILABLE — absent —
CI ready (Build) UNAVAILABLE — absent —

Check query: check-runs?per_page=100&filter=latest, 72/72 entries; no next page needed. E2E run 37654762601: 10/10 jobs; Build run 37654762599: 19/19 jobs. Actions run listing by this head returned zero despite those check-linked runs; used exact linked run IDs for bounded reconciliation. This is observed gate status, not an attestation that cached tasks executed freshly or that retries were clean.

Other risk dispositions: PERFORMANCE/RESOURCES: NOT_APPLICABLE to a dedicated benchmark in this bounded review (constant-time date helpers and one column; no new service/resource lifecycle); runtime measurement NOT_RUN. DEPLOYMENT/RECOVERY: NOT_APPLICABLE — no deployment, persistence schema, backup or restore change. PROVIDERS: NOT_APPLICABLE — no provider/connector/harness contract changes; existing auth-library proof gap remains SECURITY. OBSERVABILITY/WORKFLOW: NOT_APPLICABLE to changed implementation — no telemetry or task/run automation change. This targeted review does not replace platform-wide coverage.

Nothing outside the expiry helpers reads the 365-day ceiling, and Knip refuses an export no module imports.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

REQUEST CHANGES — API-only re-review of 0f95ef5d4ac8a0ad69bd296ffa9ec54a931ff7b6 against previously reviewed head b88f305be12a92dc96bb8a89e5a1310b30e2e757 (prior comment 6043611231). Full PR base remains 4e5a70b648e761393594f500e206da9f4f49d2b1. The old head is an ancestor; the repair comparison is complete and contains exactly one change: removing export from the maximum-lifetime constant. No test, date calculation, dialog or documentation changed.

  1. OPEN — custom dates still drift while the dialog stays open (DATA / CODE / UX-CLARITY / REL-MANUAL). services/platform/app/features/settings/api-keys/components/api-key-create-dialog.tsx:68–71 freezes openedAt until an open-state change; line 100 validates against that clock, line 131 computes the lifetime against it, and lines 135–138 send that lifetime at submission. Bounds/hints still receive openedAt at line 262. Open Oct 7, select Oct 8, then submit Oct 8: the request still sends one day and expires Oct 9; a stale/past selection still passes the opening-day validation. Fix the submission clock and refresh/revalidate stale bounds. Required regression: hold the same dialog open across midnight and multiple days, assert rejection of a now-past choice and the persisted expiry date for a still-valid choice. No such regression was added; the existing dialog expiry tests freeze one clock throughout each case.
  2. OPEN — local calendar dates still become fixed 24-hour durations across DST (DATA / CODE / UX-CLARITY / DOCS). services/platform/app/features/settings/api-keys/lib/expiry.ts:47–48 counts local calendar days, but lines 88–89 send days * 86_400 and lines 94–95 compute the hint using fixed milliseconds. api-key-expiry-field.tsx:79–84 still displays that duration's date. In Europe/Zurich, Oct 24 2026 00:30 plus two fixed days expires Oct 25 23:30 although Oct 26 was selected. Spring-forward counterpart: Mar 28 2026 23:30 plus two fixed days lands Mar 31 00:30 although Mar 30 was selected. Define a consistent chosen-date/timezone contract within the plugin's limits and verify server storage. Required regressions: both DST transitions, near-midnight creation and actual persisted-date agreement. No such regression was added; expiry.test.ts:14–51 uses a fixed Oct 7 clock and explicitly expects fixed-duration arithmetic.

Prior finding 3: Knip defect CLOSED at expiry.ts:15 (constant is now internal; line 60 remains a legitimate internal use). The existing bun run knip:check is the old-fails/new-passes regression: old job 112906942016 reports the unused export and exit 1; new job 112950875974 executes bunx knip and completes successfully. These are PR-associated executions, not local tests: old tested merge source 6af3bb9a3a2bf08b4f25e6ec247240d6613e4dae merges the old head into the stated base; new tested merge source 3f7774077e27eb405dc844b9c1f9c9ad36abd17f merges the new head into 8c99f3fd9ca17456721b23888efd55a81a6f3e2a. Thus Knip closure is supported by source inspection and the associated native CI execution, not an assertion of a standalone-head local run. The terminal-gate portion is PENDING, not closed; no CI retry/start is requested here.

New repair issues, Part A and Part B: none identified in the one-line export removal. It changes no runtime behavior, UI, locale, data schema or dependency. I inspected the complete base-to-head diff (22 files) and exact-head changed-source context. The earlier Part A/Part B limitations remain: A11Y labels/descriptions and bounds are supported by source, but keyboard/assistive, responsive/theme renders, live expiry transition and manual SET-F76 execution are NOT_RUN in this API-only slice. EN/DE/FR changed-key and {date} parity is retained; localized rendering is NOT_RUN. Docs still promise the selected day and share findings 1–2. ExpiresCell still only samples time on render (line 22), rather than scheduling a live transition. Real-plugin expiry enforcement across REST/MCP/model doors is UNAVAILABLE in this inspected evidence; this is not an observed bypass. Null expiry remains preserved. Dedicated PERFORMANCE/RESOURCES measurement is NOT_APPLICABLE to this one-line repair; runtime measurements NOT_RUN. DEPLOYMENT/RECOVERY, PROVIDERS, OBSERVABILITY and WORKFLOW changes are NOT_APPLICABLE to the repair (no changed contracts in those areas). This bounded re-review does not replace platform-wide proof or review #4501.

CICD snapshot: one complete check-runs?per_page=100&filter=latest read, 68/68 checks, no further page. Unfinished aggregators are recorded as pending without waiting. The Checks/Build/E2E terminal checks are not yet materialized; their exact-head-associated prerequisite jobs are running/queued and their source workflow definitions still declare the terminal gates. Queued child work is NOT_RUN as of this snapshot, not a product failure.

Aggregator Observed result Check ID / associated run
CI ready (Checks) PENDING — not yet materialized; prerequisite work unfinished run 37667644169
CI ready (Commitlint) PASS 112951586805
CI ready (SAST) PASS 112953315291
CI ready (Security) PASS — conditional gate; audit/Trivy scans skipped 112952282204
CI ready (CLI) PASS — conditional gate; build skipped 112951317215
CI ready (E2E) PENDING — not yet materialized; platform/docs jobs unfinished run 37667644333
CI ready (Build) PENDING — not yet materialized; platform build unfinished run 37667644198

Next owner: PR implementer repairs findings 1–2 and adds their regressions; existing CI owner/lane checks the three unfinished terminal gates after the current work settles. Successful child jobs are not substitutes for those gates, and the four PASS entries do not attest to fresh execution of every cached task. No clone, local tests, install, build, push or merge was performed.

@yannickmonney
yannickmonney enabled auto-merge (squash) October 8, 2026 16:05
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.

1 participant