API Keys Table

API keys with masked values, scopes, usage, reveal and copy, revoke and create.

PROGet API Keys Table and 168 other Pro components with pro lifetime — Get Pro

Category
Data Tables
Access
Pro
Source
416 lines · one file
States
8 drawn
Kind
Block

The decision inside it

A secret is shown once, on purpose

The full key appears only in the dialog that made it, with Copy and a line saying it won't be shown again. Revoke states the key's 30-day call count, so revoking the one production uses is never a slip.

When to use it

Use API Keys Table on a developer settings page: keys shown as prefix and last four with Reveal and Copy, scopes, 30-day calls, last used, Revoke with a confirm, and Create key that shows the new secret once.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's API Keys Table for this.
Install it: npx shadcn@latest add @liro/api-keys-table
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/api-keys-table.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Pro components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/api-keys.tsx
import { ApiKeysTable, type ApiKey } from "@/components/ui/api-keys-table";

export function ApiKeys({ rows }: { rows: ApiKey[] }) {
  return (
    <ApiKeysTable
      rows={rows}
      scopes={["documents:read", "documents:write", "webhooks"]}
      onCreate={async (name, scopes) => {
        const res = await fetch("/api/keys", { method: "POST", body: JSON.stringify({ name, scopes }) });
        return (await res.json()) as ApiKey;
      }}
      onRevoke={async (key) => {
        await fetch("/api/keys/" + key.id, { method: "DELETE" });
      }}
    />
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
rowsApiKey[] Yes–
scopesstring[] NoScopes offered in Create key.
onCreate(name: string, scopes: string[]) => ApiKey | Promise<ApiKey> NoMakes the key. Return it (with its `secret`) to show it once.
onRevoke(key: ApiKey) => void | Promise<void> NoRevokes the key. May return a promise; the dialog waits for it.
loadingboolean No–
errorReact.ReactNode No–
onRetry() => void No–
onRowClick(row: ApiKey) => void No–
density"comfortable" | "compact" No–
variant"default" | "striped" | "bordered" No–
nowDate No"Now" for "last used", for tests and screenshots. Default the current time.
classNamestring No–

Dependencies

npm packages

clsxlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-themebadgebuttoncheckboxdata-tabledialogfieldinputtooltip

States

All of them are drawn by the component. None is left for you to design.

  • Active keys
  • Reveal and copy
  • Revoke confirm
  • Create key
  • Revoked
  • Loading
  • Empty
  • Error

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances

Used in a screenAll screens