Auth card
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.
Dependencies
Interaction 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 thin line 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.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/auth-cardFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
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.
What it handles
- 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.
Usage
Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.
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")}
/>Props
| Prop | Type | 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. |
Accessibility & motion
- 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.
pnpm dlx shadcn@4.21.5 add @cavemio/auth-card