# One-time code

- **[App UI](/app/)**
- **[Authentication](/app/auth/)**
- **One-time code**

Enter a six-digit code: six boxes that behave as one field.

## Notes

- **When to use it**: The step after sign-in or sign-up where someone types a six-digit code from an email or text. For choosing a new password use `app-auth-reset`; for the first sign-in step use `app-auth-signin`.
- **Writing for it**: - `codeLabel` (40 characters) names the group of boxes, and each box is read as `digitLabel`, its number, `of` and 6. Keep `digitLabel` to a single word such as Digit.
- The `description` (300) is the place to say where the code was sent and how long it lasts; the box count is fixed at six, so do not promise any other length.
- Write `messages.error` and `messages.resent` as full sentences up to 120 characters. The resent text appears after someone presses the resend button, even when the state prop is idle.
- **Watch out for**: Nothing is sent unless the host gives the block an `action` or handles the submit, because it behaves as a form with optional method, hidden fields and captcha. While the state is verifying the boxes are read-only, so a stuck verifying state locks people out.

## Pairs well with

- **[App, sign in](/blocks/app/auth-signin)**
- **[App, sign up](/blocks/app/auth-signup)**
- **[App, reset password](/blocks/app/auth-reset)**

## Usage

The block in a page, with its default content (long lists shortened). Every prop is in the table below.

section.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { BlockSurface } from '@/components/klarhimmel/blocks/surface';
import AppAuthCode from '@/components/klarhimmel/blocks/app-auth-code';

export default function Section() {
  return (
    <Theme theme="brand">
      <BlockSurface>
        <AppAuthCode props={{
          "eyebrow": "Name the section",
          "title": "Check your email",
          "description": "Say where the code was sent and how long it works.",
          "codeLabel": "Name the code",
          "digitLabel": "Digit",
          "of": "of",
          "submit": "Verify",
          "verifying": "Verifying…",
          "resend": "Send a new code",
          "state": "idle",
          "messages": {
            "error": "Say that the code is wrong or has expired and what to do next.",
            "resent": "Say a new code was sent."
          }
        }} />
      </BlockSurface>
    </Theme>
  );
}
```

## Props

The code is always six digits. codeLabel names the group, digitLabel and of name each box ("Digit 1 of 6"); state sets verifying, error and resent.

- **eyebrow**: Text, up to 60 characters. Optional; empty is not rendered.
- **title**: Text, up to 120 characters.
- **description**: Text, up to 300 characters. Optional; empty is not rendered.
- **codeLabel**: Text, up to 40 characters.
- **digitLabel**: Text, up to 20 characters.
- **of**: Text, up to 10 characters.
- **submit**: Text, up to 30 characters.
- **verifying**: Text, up to 30 characters.
- **resend**: Text, up to 30 characters.
- **state**: One of 'idle', 'verifying', 'error', 'resent'.
- **messages**: Fields: error, resent.
- **action**: Text, up to 300 characters. Optional; empty is not rendered.
- **method**: One of 'post', 'get'. Optional; empty is not rendered.
- **hidden**: Optional; empty is not rendered.
- **captcha**: Optional; empty is not rendered.
- **captchaSitekey**: Text, up to 100 characters. Optional; empty is not rendered.
- **headingLevel**: One of '1', '2'. Optional; empty is not rendered.

## Install

- **CLI**

  ```
  npx shadcn add @klarhimmel/app-auth-code
  ```

Uses

- Banner
- Button

- **About**: Enter a six-digit code: six boxes that behave as one field. Typing moves forward, Backspace moves back, arrow keys move, pasting fills every box, and the first box asks for the one-time code autofill.
- **States**: Idle, verifying, error, resent. Six boxes act as one: paste, Backspace and arrow keys work. New project? Set it up once: /get-started/installation.
