# Passkey button

> A biometric passkey button whose 9-ridge fingerprint scans optically ridge by ridge while pending, then sweeps an 8×8 Bayer wave across the pill as the ridges draw into a check.

Most passkey buttons pair a static fingerprint icon with a generic spinning circle, giving no tactile feedback while the browser waits on Touch ID, Face ID or a security key. This turns the button into a physical optical sensor. Inside a recessed circular well sits a custom 9-ridge hairline fingerprint that wakes softly on hover. Pressing triggers your WebAuthn promise: an optical laser scanline sweeps vertically across the ridges, lighting each ridge and four minutiae junction dots in turn while a subtle 8×8 ordered Bayer band glides across the pill behind the morphing label. When the credential verifies, the nine ridges compress inward and collapse along their strokes straight into a self-drawing emerald checkmark as a crisp emerald-to-mint Bayer wavefront sweeps left-to-right across the button and dissolves to 0% CPU rest. If the prompt is cancelled or rejected, a crimson Bayer recoil snaps back into the well, the button gives a tight damped shake, the label morphs to Try again and the error reason folds cleanly underneath.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/passkey-button.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `text-morph`
- Docs and live preview: https://hairlineui.com/ui/passkey-button
- Registry item (source): https://hairlineui.com/r/passkey-button.json

## Usage

```tsx
import { PasskeyButton } from "@/components/passkey-button";

<PasskeyButton onVerify={() => signInWithPasskey()} />
```

## Wiring WebAuthn navigator.credentials.get()

Fetch a challenge from your server, call navigator.credentials.get(), and post the assertion back. Throwing an Error displays the message cleanly under the button and lets the user retry.

```tsx
"use client";
import { useRouter } from "next/navigation";
import { PasskeyButton } from "@/components/passkey-button";

export function PasskeySignIn() {
  const router = useRouter();

  async function verifyPasskey() {
    const optionsRes = await fetch("/api/auth/passkey/options");
    if (!optionsRes.ok) throw new Error("Could not start passkey sign-in.");
    const publicKey = await optionsRes.json();

    const credential = await navigator.credentials.get({ publicKey }).catch(() => null);
    if (!credential) throw new Error("Passkey prompt was cancelled on this device.");

    const verifyRes = await fetch("/api/auth/passkey/verify", {
      method: "POST",
      headers: { "content-type": "application/json" },
      body: JSON.stringify(credential),
    });
    if (!verifyRes.ok) throw new Error("Could not verify this passkey.");
    router.push("/dashboard");
  }

  return <PasskeyButton onVerify={verifyPasskey} fullWidth sound />;
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onVerify` | `() => void \| Promise<unknown>` | – | Your WebAuthn / passkey verification call. Resolving marks verified; rejecting enters error and surfaces Error.message inline. |
| `status / onStatusChange` | `"idle" \| "scanning" \| "verified" \| "error" / (s) => void` | `"idle"` | Optional controlled status if your auth store drives the state directly. |
| `variant` | `"surface" \| "primary" \| "outline"` | `"surface"` | Card hairline pill, solid brand primary CTA or transparent outline. |
| `size` | `"default" \| "lg"` | `"default"` | 46px standard button or 54px hero authentication button. |
| `fullWidth` | `boolean` | `false` | Stretches the pill across a sign-in card instead of easing its width with TextMorph. |
| `labels` | `Partial<Record<PasskeyStatus, string>>` | `Sign in with passkey / Verifying passkey / Verified / Try again` | Custom labels for each state. |
| `errorMessage` | `ReactNode` | – | Explicit error message override shown under the pill when status is "error". |
| `resetAfter / onReset` | `number / () => void` | `0` | Milliseconds after verified to automatically reset back to idle (0 keeps verified). |
| `sound / disabled` | `boolean / boolean` | `false / false` | Opt-in quiet Web Audio cues on press, verified and error (from ui-sounds.ts), plus standard disabled handling. |

## States

- **idle**: A quiet hairline pill with a 9-ridge fingerprint inside a concentric recessed sensor well; hovering wakes the ridges to higher ink contrast while the canvas sleeps at 0% CPU.
- **scanning**: Triggered while onVerify() is pending. A vertical optical beam sweeps smoothly across the 9 ridges (~1.35s ping-pong), illuminating individual ridges and four minutiae lock points while a subtle 8×8 Bayer band glides across the pill and TextMorph eases the label to Verifying passkey.
- **verified**: The 9 ridges retract radially over 260ms into a self-drawing emerald checkmark inside the sensor well while an 8×8 Bayer emerald-to-mint wavefront sweeps left-to-right across the pill (~640ms) and dissolves to rest.
- **error**: A crimson Bayer recoil snaps back toward the sensor well (~420ms), the pill executes a 360ms damped horizontal shake, the label morphs to Try again and the error message folds open cleanly beneath the button.
- **reduced motion**: No scan loop, Bayer sweep or shake: each state renders one static settled optical frame and swaps cleanly in place.

## What it handles

WebAuthn flows sit in an awkward silent pause while the OS biometric sheet is open, and fail abruptly when dismissed. This owns the scanning feedback, verified transition, error recovery and width morph around a single Promise.

- **One async prop**: Pass onVerify returning a Promise; the button manages idle, scanning, verified and error automatically, or accepts a controlled status.
- **9-ridge optical biometric scan**: Each fingerprint ridge and four minutiae lock points illuminate individually as a vertical scan beam passes over them at 60fps.
- **Ridges-to-check synthesis**: On verification the nine ridges retract radially along their strokes straight into a self-drawing emerald checkmark inside the sensor well.
- **8×8 Bayer verification wavefront**: A zero-GC Uint32Array Bayer field sweeps emerald-to-mint left-to-right across the pill on success, then puts the frame loop completely to sleep.
- **Graceful cancellation recovery**: Rejected promises trigger a crimson recoil, a damped shake, a TextMorph swap to Try again and an inline role="alert" reason.
- **Light, dark and primary surfaces**: Calibrated across surface, outline and solid primary variants with zero external icon dependencies and reduced-motion still frames.

## Replaces

passkey login button, biometric auth button, WebAuthn button, fingerprint spinner, framer-motion

## Where it fits

- **Passwordless sign-in**: Drop directly onto a login screen wired to navigator.credentials.get() or Better Auth passkeys.
- **Payout and transfer confirmation**: Confirm high-value actions with Touch ID or Face ID, showing a clear optical lock when verified.
- **Account security settings**: Register or test a device passkey with clear scanning, verified and cancelled feedback.
- **Step-up re-authentication**: Verify identity before revealing API keys, billing details or destructive workspace actions.

## Notes

- Zero external icon packages: the 9-ridge fingerprint sensor, minutiae dots, scan beam and self-drawing checkmark are pure inline SVG.
- The 8×8 Bayer optical canvas writes directly into a Uint32Array offscreen buffer and sleeps completely at 0% CPU whenever idle, verified or settled after error.
- Label width eases smoothly through TextMorph when fullWidth is false; aria-busy is set while scanning, status changes announce in a polite aria-live region and errors use role="alert".
- Under prefers-reduced-motion: reduce, the frame loop and shake are disabled and states update cleanly in place.

License: MIT (https://hairlineui.com/license#components)
