# Key reveal once

A new secret, shown once, with copy, a .env line and a check before it is closed uncopied.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Key reveal once. A new secret shown once, with copy, a .env line, and a check when closing before copying. Preview: https://chatcn.dev/preview/key-reveal-once-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/key-reveal-once
```

## Usage

```tsx
import { KeyRevealOnce } from "@/components/ui/chatcn/pro/key-reveal-once"

{secret ? (
  <KeyRevealOnce
    secret={secret}
    name="Production server"
    envName="CHATCN_API_KEY"
    onDone={() => setSecret(null)}
  />
) : null}
```

Says plainly that this is the only time the secret is shown. The secret is set in mono with copy beside it, it can be hidden while someone looks over a shoulder, and with `envName` a ready `NAME=secret` line can be copied too. Closing before anything was copied asks once, in place, because a lost key means making a new one. Render it only while the secret should be visible and drop the secret in `onDone`. `api-keys` uses it for new and rotated keys.

## Examples

### States

Example: States. Without a variable name, in a narrow frame where a long secret scrolls inside its field. Preview: https://chatcn.dev/preview/key-reveal-once-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `secret` | `string` | The new secret |
| `name` | `string` | The key's name, under the title |
| `envName` | `string` | Offers a `.env` line |
| `onDone` | `() => void` | Closing; forget the secret here |
| `labels` | `Partial<KeyRevealOnceLabels>` | Every string, for translation |

## Accessibility

- Copy buttons announce when they have copied.
- Hide is a toggle button that reports its state.
- Closing uncopied raises an alert with Go back focused.

## Motion

The copy icon crossfades to a check. Nothing else moves.

Source: https://chatcn.dev/docs/components/key-reveal-once