# 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.

Source: https://www.honestui.com/docs/product/secret-row

```tsx
"use client"

import * as React from "react"

import {
  SecretList,
  SecretRow,
  type SecretRowSecret,
} from "@/registry/default/product/secret-row/secret-row"

// A fixed clock, so the relative times read the same on every visit.
const now = Date.parse("2026-11-26T15:00:00Z")
const hour = 60 * 60 * 1000
const day = 24 * hour

const sampleKeys: SecretRowSecret[] = [
  {
    id: "key_prod",
    name: "Production server",
    prefix: "hk_live_",
    last4: "3f9a",
    createdAt: now - 214 * day,
    lastUsedAt: now - 2 * 60 * 1000,
    scopes: ["orders:read", "orders:write", "refunds:write"],
  },
  {
    id: "key_ci",
    name: "CI pipeline",
    prefix: "hk_live_",
    last4: "c07e",
    createdAt: now - 41 * day,
    lastUsedAt: now - 5 * hour,
    expiresAt: now + 49 * day,
    scopes: ["orders:read"],
  },
  {
    id: "key_local",
    name: "Local development",
    prefix: "hk_test_",
    last4: "91d2",
    createdAt: now - 3 * day,
    lastUsedAt: null,
    scopes: ["orders:read", "customers:read"],
  },
]

/** Stand-in for the server: values are made up here and only handed over on request. */
const values: Record<string, string> = {
  key_prod: "hk_live_4eC39HqLyjWDarjtT1zdp7dc3f9a",
  key_ci: "hk_live_9vNq2RkPz7uYbXm3TgLs0hWfc07e",
  key_local: "hk_test_Fh2kLp9QzRm4WnYt7Vb1xJe891d2",
}

function wait(milliseconds: number) {
  return new Promise((resolve) => window.setTimeout(resolve, milliseconds))
}

function randomTail(length: number) {
  const alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789"
  return Array.from({ length }, () => alphabet[Math.floor(Math.random() * alphabet.length)]).join("")
}

export function SecretRowDemo() {
  return (
    <SecretList aria-label="API keys" className="max-w-xl">
      {sampleKeys.map((key) => (
        <SecretRow
          key={key.id}
          secret={key}
          now={now}
          onReveal={async (secret) => {
            await wait(350)
            return values[secret.id] ?? ""
          }}
          onRotate={async (secret) => {
            await wait(900)
            const value = `${secret.prefix ?? ""}${randomTail(28)}`
            values[secret.id] = value
            return { value }
          }}
          onRevoke={() => wait(700)}
        />
      ))}
    </SecretList>
  )
}

```

## Overview [#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 [#anatomy]

<Anatomy title="SecretRow">
  <AnatomyItem name="SecretList" description="Optional. Stacks rows into one bordered list" />

  <AnatomyItem name="SecretRow" description="One key">
    <AnatomyItem name="Name" description="What the person called the key, with a status badge when it is revoked or expired" />

    <AnatomyItem name="Value" description="Masked as prefix, bullets, and last four characters; the full value when shown" />

    <AnatomyItem name="Meta" description="Created date, last used time, and expiry" />

    <AnatomyItem name="Scopes" description="One badge per scope" />

    <AnatomyItem name="Actions" description="Show, Copy, Rotate, and Revoke, each only when supplied" />

    <AnatomyItem name="Panel" description="The confirm step for Rotate or Revoke, then the new value once" />

    <AnatomyItem name="Message" description="A polite status line for copies, rotations, and failures" />
  </AnatomyItem>
</Anatomy>

Installing `secret-row` brings `Badge`, `Button`, and `Tooltip` along as registry dependencies.

## Behavior [#behavior]

### Masking and revealing [#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 [#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 [#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 [#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 [#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 [#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 [#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. <kbd>Escape</kbd> 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.

| Key                                  | Action                                                             |
| ------------------------------------ | ------------------------------------------------------------------ |
| <kbd>Tab</kbd>                       | Move across Show, Copy, Rotate, and Revoke, then through the panel |
| <kbd>Enter</kbd> or <kbd>Space</kbd> | Activate the focused button                                        |
| <kbd>Escape</kbd>                    | Close the confirm panel and return to its trigger                  |

## Installation [#installation]


  

  
    <CliBlock commands="[&#x22;secret-row&#x22;]" />
  

  
    
      
        No extra packages are needed beyond the base setup.
      

      
        Copy and paste these files into your project.
      

      <ComponentSource name="secret-row" title="components/ui/secret-row/secret-row-types.ts" file="secret-row-types.ts" />

      <ComponentSource name="secret-row" title="components/ui/secret-row/secret-row-utils.ts" file="secret-row-utils.ts" />

      <ComponentSource name="secret-row" title="components/ui/secret-row/secret-row.tsx" file="secret-row.tsx" />

      
        Update the import paths to match your project setup.
      
    
  


## Usage [#usage]

```tsx
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:

```tsx
<SecretRow secret={{ id: "whsec_1", name: "Signing secret", prefix: "whsec_", last4: "8b1c", createdAt }} />
```

### After a rotation [#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 [#dont-do-this]

### Sending every value to the page [#sending-every-value-to-the-page]

```tsx
// 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 [#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 [#examples]

### Keys the page cannot read [#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.

```tsx
"use client"

import * as React from "react"

import {
  SecretList,
  SecretRow,
  type SecretRowSecret,
} from "@/registry/default/product/secret-row/secret-row"

const now = Date.parse("2026-11-26T15:00:00Z")
const day = 24 * 60 * 60 * 1000

/**
 * Keys the page can only describe: the server never returns their values,
 * so there is no Show or Copy. Rotation fails the first time it is tried.
 */
const sampleKeys: SecretRowSecret[] = [
  {
    id: "whsec_billing",
    name: "Billing webhook",
    prefix: "whsec_",
    last4: "8b1c",
    createdAt: now - 380 * day,
    lastUsedAt: now - 12 * day,
    scopes: ["invoice.paid", "invoice.failed"],
  },
  {
    id: "key_legacy",
    name: "Legacy importer",
    prefix: "hk_live_",
    last4: "a4e0",
    createdAt: now - 720 * day,
    lastUsedAt: now - 95 * day,
    expiresAt: now - 4 * day,
  },
  {
    id: "key_contractor",
    name: "Contractor access",
    prefix: "hk_live_",
    last4: "5d77",
    createdAt: now - 160 * day,
    lastUsedAt: now - 60 * day,
    status: "revoked",
  },
]

function wait(milliseconds: number) {
  return new Promise((resolve) => window.setTimeout(resolve, milliseconds))
}

export function SecretRowStates() {
  const attempts = React.useRef(0)

  return (
    <SecretList aria-label="Webhook and legacy keys" className="max-w-xl">
      {sampleKeys.map((key) => (
        <SecretRow
          key={key.id}
          secret={key}
          now={now}
          onRotate={async (secret) => {
            await wait(800)
            attempts.current += 1
            if (attempts.current === 1) throw new Error("Rotation failed")
            return { value: `${secret.prefix ?? ""}Qm7Tz2LpX9cV4nB8wR1yK6hD3sF0` }
          }}
        />
      ))}
    </SecretList>
  )
}

```

## API reference [#api-reference]

### SecretRow [#secretrow]

Accepts native div props beyond those listed. Inside `SecretList` it renders a list item.

| Prop       | Type                                    | Default           | Description                                                                  |
| ---------- | --------------------------------------- | ----------------- | ---------------------------------------------------------------------------- |
| `secret`   | `SecretRowSecret`                       | Required          | The key to show.                                                             |
| `onReveal` | `(secret) => Promise<string> \| string` | None              | Loads the full value. Needed for Show and Copy unless `secret.value` is set. |
| `onCopy`   | `(secret) => void`                      | None              | Runs after a successful copy.                                                |
| `onRotate` | `(secret) => Promise<SecretRotation>`   | None              | Creates a replacement key. Passing it offers Rotate.                         |
| `onRevoke` | `(secret) => Promise<unknown>`          | None              | Revokes the key. Passing it offers Revoke.                                   |
| `now`      | `Date \| number`                        | The time of mount | What relative times and expiry are measured from.                            |
| `locale`   | string                                  | The browser's     | Used for dates and relative times.                                           |
| `labels`   | `Partial<SecretRowLabels>`              | English           | Every visible word and accessible name.                                      |

### SecretList [#secretlist]

A `ul` with native props. Give it an `aria-label`.

### Types [#types]

| Export            | Shape                                                                                                                                |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `SecretRowSecret` | `id`, `name`, `createdAt`, and optional `prefix`, `last4`, `value`, `lastUsedAt` (`null` for never), `expiresAt`, `scopes`, `status` |
| `SecretRotation`  | `value`, and optional new `prefix` and `last4`                                                                                       |
| `SecretRowStatus` | `"active"`, `"revoked"`, or `"expired"`                                                                                              |

### Helpers [#helpers]

| Export                                    | Description                                                     |
| ----------------------------------------- | --------------------------------------------------------------- |
| `maskSecret(secret, maskLength?)`         | The masked string: prefix, bullets, and last four characters.   |
| `formatRelativeTime(date, now?, locale?)` | "5 minutes ago", "yesterday", or "in 3 days".                   |
| `getSecretStatus(secret, now?)`           | `revoked`, `expired` (including past `expiresAt`), or `active`. |
