Secret Row
Show an API key or secret with its value masked, and let people reveal, copy, rotate, or revoke it with a confirm step and the new value shown once.
Overview
Secret Row is one API key, token, or signing secret on a settings page. It shows the name, the value masked with its start and end still visible, when the key was created and last used, and the scopes it carries.
The start and end are what people match against: a log line that mentions hk_live_โฆ3f9a, or a dashboard of another service. The masked middle never follows the real length of the key, so the row does not leak it.
Every action is opt-in. Show and Copy appear when the page has the value or can fetch it with onReveal. Rotate appears when you pass onRotate, and Revoke when you pass onRevoke. A key that is revoked or past its expiry keeps its row, so the history stays readable, but loses its actions.
Secret Row does not store keys, call your API, or decide who may see a value. Your handlers do that, and the row reports what they return.
Anatomy
- SecretListOptional. Stacks rows into one bordered list
- SecretRowOne key
- NameWhat the person called the key, with a status badge when it is revoked or expired
- ValueMasked as prefix, bullets, and last four characters; the full value when shown
- MetaCreated date, last used time, and expiry
- ScopesOne badge per scope
- ActionsShow, Copy, Rotate, and Revoke, each only when supplied
- PanelThe confirm step for Rotate or Revoke, then the new value once
- MessageA polite status line for copies, rotations, and failures
Installing secret-row brings Badge, Button, and Tooltip along as registry dependencies.
Behavior
Masking and revealing
The masked value is prefix, twelve bullets, and last4. Pass those two parts from your API; most providers return them for exactly this purpose. When the page already has the full value, pass it as value and the last four characters are taken from it.
Show fetches the value through onReveal the first time and keeps it for the life of the row, so hiding and showing again does not call your server twice. While the request is in flight the button shows a spinner. A failed reveal leaves the value masked and says so in the message line.
Copying
Copy writes the full value to the clipboard, fetching it first if needed, without revealing it on screen. The icon turns into a check for two seconds and the message line says the value was copied. onCopy runs after a successful copy, for an audit trail.
Rotating
Rotate asks first, because the old key stops working. On confirm, onRotate creates the replacement and resolves with its value. The panel then shows the new value in full, once, with a button to copy it. After Done, the row masks the new value with its own last four characters.
If onRotate rejects, the panel stays open on the confirm step and the message line says the key still works.
Revoking
Revoke also asks first, and its confirm button is styled as destructive. On success the row keeps its place with a Revoked badge, a struck-through value, and no actions.
Expiry
A key whose expiresAt has passed is shown as expired even if your API still reports it as active. Before then, the expiry date appears in the meta line.
Relative times
Last used reads as "2 minutes ago" or "yesterday", in the given locale. Pass now when the row is rendered on the server, so the server and the browser write the same words.
Accessibility
Each icon button has a name that includes the key, such as "Copy Production server", and a tooltip with the short verb. Show is a toggle button with aria-pressed, and it controls the value it reveals.
While masked, the bullets are hidden from screen readers and the value is read by its visible parts instead: "hk_live_, hidden, ending in 3f9a".
The confirm panel is a labelled group that takes focus when it opens: Cancel for a confirm step, and Copy new key after a rotation. Escape closes it and returns focus to the button that opened it.
Copies, rotations, and failures are announced through one polite status line that stays mounted. Failures carry an icon and words, never color alone.
Installation
Usage
import { SecretList, SecretRow } from "@/components/ui/secret-row/secret-row"
<SecretList aria-label="API keys">
{keys.map((key) => (
<SecretRow
key={key.id}
secret={key}
onReveal={(secret) => api.revealKey(secret.id)}
onRotate={(secret) => api.rotateKey(secret.id)}
onRevoke={(secret) => api.revokeKey(secret.id)}
/>
))}
</SecretList>A key on its own, outside a list, renders as its own card:
<SecretRow secret={{ id: "whsec_1", name: "Signing secret", prefix: "whsec_", last4: "8b1c", createdAt }} />After a rotation
onRotate resolves with { value }, plus prefix and last4 if they changed. Refetch your list afterwards so the row's secret describes the new key; the row then forgets the old value.
Don't do this
Sending every value to the page
// Bad. Every full key is in the page's HTML, whether or not anyone asks to see it.
<SecretRow secret={{ ...key, value: key.fullValue }} />Pass prefix and last4, and fetch the value with onReveal when someone asks. Better still, show it only once, at creation or rotation, and never again.
Rotating without a way to copy
Do not close the panel or navigate away as soon as onRotate resolves. The new value is shown once, and the person needs it before the old key stops working.
Examples
Keys the page cannot read
Webhook secrets and old keys whose values the server never returns again. There is no Show or Copy. One key has expired and one was revoked, and rotating the first fails once before it succeeds.
API reference
SecretRow
Accepts native div props beyond those listed. Inside SecretList it renders a list item.
SecretList
A ul with native props. Give it an aria-label.