API Keys

Credentials, listed and revocable. A key is shown in full exactly once — after that only the prefix and last four, because a list that can reveal every key means a session holds every secret.

src/components/ui/api-keys.tsx

About

From the component's own source, where it was written.

API credentials, listed and revocable.

A key is shown in full exactly once — when it is created. After that only the prefix and last four characters are available, because a list that can reveal every key on demand means anyone with a session has every secret. secret is therefore optional and expected to be absent for existing keys.

Revoking is confirmed inline rather than in a dialog. The confirmation needs to sit beside the key it affects — a modal saying "revoke this key?" with the list hidden behind it is how the wrong one gets revoked.

Install

npx astralyx-ui add api-keys

Usage

import { ApiKeys } from '@/components/ui/api-keys'

<ApiKeys keys={keys} onRevoke={revoke} />

Composer

Change the props and the source below follows.

  • Productionreadwrite
    ax_live_••••••••a91f

    Created Last used

  • CI runnerread
    ax_live_••••••••4c2e

    Created Last used

  • Local developmentCopy it now
    ax_test_••••••••7b10

    Created Never used

Props
tsx
<ApiKeys keys={keys} onRevoke={revoke} />

Examples

Keys

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

ApiKeys

Extends Omit<ComponentProps<'div'>, 'children'>.

PropTypeDefaultDescription
keysApiKey[]required{ id, name, prefix, last4, created, lastUsed?, scopes?, secret? }.
onRevoke(id: string) => void—Confirmed inline beside the key — a modal with the list hidden behind it is how the wrong key gets revoked.
nowDate——
emptyLabelReactNode'No API keys yet'—
freshLabelReactNode'Copy it now'Badge on a key whose secret is still visible.
revealLabelstring'Reveal key'—
hideLabelstring'Hide key'—
copyLabelstring'Copy key'—
revokeLabelReactNode'Revoke'—
revokeActionLabel(name: string) => stringDEFAULT_REVOKE_ACTION_LABELAccessible name for the revoke control, given the key's name.
createdLabelReactNode'Created'—
lastUsedLabelReactNode'Last used'—
neverUsedLabelReactNode'Never used'—
confirmNoteReactNode'Revoking is immediate and cannot be undone.'—
cancelLabelReactNode'Cancel'—

Types

ApiKey

API credentials, listed and revocable.

FieldTypeDescription
idstring—
namestring—
prefixstringShown as sk_live_…abcd.
last4string—
createdDate—
lastUsed?Date—
scopes?string[]—
secret?stringPresent only for a key just created. Its absence is what makes older keys unrevealable rather than a UI choice.