# Auth card

> Sign-in that asks one thing at a time: the email field shrinks into a chip round the address, and your server decides whether a password, a code or a link comes next.

Most sign-in forms show every field at once, or swap whole screens with a flash between them. This one asks one thing at a time, the way identifier-first sign-in works at Google and Clerk: providers, then your email, and your server says what comes next (a password, a code or a link). The email field doesn't go anywhere. Its frame shrinks round the address into a chip as the providers fold away above it, and "Change" opens at its end to take you back. Each next step slides in from the right while the card eases to its new height, and titles lift out and in. Codes are checked as the last digit lands. A link step has a button that opens the inbox itself for Gmail, Outlook, iCloud, Yahoo and Proton addresses. Done draws a ring and a check. The card never calls a service: every step is one async function.

## Install

```bash
npx shadcn@latest add @hairline/auth-card
```

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

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `code-input`, `number-roll`, `status-button`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/auth-card
- Registry item (source): https://hairlineui.com/r/auth-card.json

## Usage

```tsx
import { AuthCard } from "@/components/auth-card";

<AuthCard
  onEmail={async (email) => (await hasPassword(email) ? "password" : "code")}
  onPassword={(email, password) => signIn(email, password)}
  onCode={(email, code) => verify(email, code)}
  onSuccess={() => router.push("/app")}
/>
```

## With Better Auth: password or a one-time code

A route on your server says which step an address needs. A one-time code goes out through the email OTP plugin; providers use social sign-in, which redirects. Any thrown error's message is what the card shows. Clerk's custom flows, Supabase Auth and Auth.js fit the same four functions.

```tsx
"use client";
import { useRouter } from "next/navigation";
import { AuthCard } from "@/components/auth-card";
import { authClient } from "@/lib/auth-client";
import { GoogleIcon } from "@/components/icons";

const check = <T,>(r: { error: { message?: string } | null; data: T }) => {
  if (r.error) throw new Error(r.error.message ?? "That didn't work.");
  return r.data;
};

export function SignIn() {
  const router = useRouter();
  return (
    <AuthCard
      providers={[{ id: "google", label: "Google", icon: <GoogleIcon /> }]}
      onProvider={(provider) => authClient.signIn.social({ provider, callbackURL: "/app" })}
      onPasskey={async () => check(await authClient.signIn.passkey())}
      onEmail={async (email) => {
        const res = await fetch("/api/auth/next-step", { method: "POST", body: JSON.stringify({ email }) });
        const { step } = await res.json(); // "password" | "code"
        if (step === "code") check(await authClient.emailOtp.sendVerificationOtp({ email, type: "sign-in" }));
        return step;
      }}
      onPassword={async (email, password) => check(await authClient.signIn.email({ email, password }))}
      onCode={async (email, otp) => check(await authClient.signIn.emailOtp({ email, otp }))}
      onResend={async (email) => check(await authClient.emailOtp.sendVerificationOtp({ email, type: "sign-in" }))}
      onForgot={async (email) => check(await authClient.requestPasswordReset({ email, redirectTo: "/reset" }))}
      onSuccess={() => router.push("/app")}
      footer={<>No account yet? <a href="/sign-up">Create one</a></>}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onEmail` | `(email) => Promise<"password" \| "code" \| "link">` | – | Asks your server what this address needs next (and sends the code or link if that's it). Throw to keep the field and show the message. |
| `onPassword` | `(email, password) => Promise<unknown>` | – | Signs in with a password. Throw when it's wrong. |
| `onCode` | `(email, code) => Promise<unknown>` | – | Checks a one-time code. Resolve when it's right; throw when it isn't. |
| `onResend` | `(email) => Promise<unknown>` | – | Sends the code or link again. Without it there is no resend. |
| `onForgot` | `(email) => Promise<unknown>` | – | Sends a password reset link; shows "Forgot password?" on the password step. |
| `providers` | `{ id, label, icon? }[]` | – | Sign-in providers above the email field, two to a row. |
| `onProvider` | `(id) => Promise<unknown>` | – | Starts a provider's sign-in. A redirect keeps its button spinning; a popup that resolves moves the card to done. |
| `onPasskey` | `() => Promise<unknown>` | – | Shows "Sign in with a passkey" and sets the email field's autocomplete to "username webauthn" for passkey autofill. |
| `onSuccess` | `() => void` | – | Runs after "Signed in" has shown, e.g. to redirect. |
| `mode` | `"sign-in" \| "sign-up"` | `"sign-in"` | Sets the default words and the password field's autocomplete. |
| `copy` | `Partial<Record<step, { title?, description? }>>` | – | Words per step: email, password, code, link, reset and done. |
| `logo` | `ReactNode` | – | Above the title. |
| `footer` | `ReactNode` | – | Under the email step: a link to sign up, terms. It folds away after the first step. |
| `defaultEmail` | `string` | – | Starts the field with an address, e.g. from an invite link. |
| `codeLength` | `number` | `6` | Digits in a one-time code. |
| `resendAfter` | `number` | `30` | Seconds before a code or link can be sent again. |

## States

- **email**: Providers (two to a row), "or", then the email field and Continue. An address that isn't one shakes the field and says so under it; a passkey button sits under Continue when onPasskey is set.
- **checking**: Continue morphs to "Checking" with a spinner while onEmail runs. If it throws, the field shakes ±4px, its hairline turns red and the message opens under it.
- **identity**: The field's frame eases from full width and 40px to the address's own width and 32px, its corners to a pill, in 520ms; the address stays where it was typed. The providers fold up above it in 460ms and "Change" opens at its end 160ms later.
- **next step**: The new step slides in 28px from the right out of a 4px blur (440ms) while the old one leaves the other way; the card eases to its new height. Change runs it backwards and selects the address.
- **password**: A password field with a show/hide eye that swaps through a blur. A wrong password shakes the field, selects it and says why. "Forgot password?" morphs to "Sending a link" and moves on to Check your inbox.
- **code**: The code boxes (code input): digits rise in, the row sweeps while onCode runs, a wrong code shakes and clears, a right one melts into one pill; then the card moves on. Resend counts down.
- **link**: "Check your inbox", with "Open Gmail" (or Outlook, iCloud Mail, Yahoo Mail, Proton Mail) for addresses it knows, and "Resend in 0:28" rolling down to Resend.
- **providers**: The pressed provider's mark gives way to a spinner while the others dim. If onProvider throws, the reason opens under the field; if it resolves (a popup), the card moves to done.
- **done**: A ring draws itself in 640ms, then a check inside it; "Signed in". onSuccess runs 1.3s later, e.g. to redirect.

## What it handles

Most sign-in forms show every field at once or swap whole screens with a flash in between. This one asks for one thing at a time, and your server decides whether a password, a code or a link comes next.

- **Your server picks the next step**: onEmail answers “password”, “code” or “link” for each address, and the card moves on.
- **The email becomes a chip**: The field shrinks round the address, and Change takes you back to edit it.
- **Codes check themselves**: The code is sent for checking as the last digit lands. A wrong one shakes and clears, and Resend counts down.
- **It opens the inbox for you**: A link step offers “Open Gmail”, and the same for Outlook, iCloud, Yahoo and Proton addresses.
- **Providers and passkeys**: Provider buttons sit above the email field, and a passkey button appears when you pass onPasskey.
- **Any auth service fits**: The card never calls a service or stores a password. Every step is one async function you connect.

## Replaces

a multi-step form, step transitions, a one-time code input, a resend timer, provider and passkey buttons

## Where it fits

- **Sign-in and sign-up pages**: One card for passwords, one-time codes and magic links, asked one step at a time.
- **Passwordless login**: Email a code or a link as the main way in, with no password field to fill.
- **Social login**: Google or GitHub buttons above the email field, two to a row.
- **Invite links**: Open with the invited address already in the field.

## Notes

- It is one form: Enter continues from the email field and signs in from the password field. The address is a real email input (autocomplete="email", or "username webauthn" with passkeys) and stays one, read-only, while it's a chip; Change is a button at its end.
- Each step moves focus to what comes next: the password field, the first code box, or the Open inbox button. Change returns focus to the address and selects it. Every new step's title is announced in a status region.
- Errors are linked to their field with aria-describedby and the field is marked aria-invalid. The resend countdown is hidden from screen readers; the button says when it can be used.
- The card never stores the password or code and never calls a service itself.
- Inputs use 16px type on touch screens so phones don't zoom into them.
- Reduced motion changes steps in place: no shrinking frame, slides, shakes or drawing; the words still say what happened.

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