Skip to content

Auth Verify

Email verification screen: mail icon, six single-digit mono boxes (split 3 + 3) with auto-advance, paste, arrow/backspace navigation, auto-submit, error and success states and a resend countdown.

minimal/layout/auth-verify
Open ↗

Source

"use client";

import { useEffect, useId, useRef, useState, type ClipboardEvent, type KeyboardEvent } from "react";
import { MailCheck } from "lucide-react";
import { cn } from "@/lib/utils";

export interface AuthVerifyProps {
  email?: string;
  length?: number;
  /** Called when all digits are entered; throw to show an error and clear. */
  onComplete?: (code: string) => void | Promise<void>;
  onResend?: () => void;
  /** Seconds before “Resend” is available. */
  cooldown?: number;
  backHref?: string;
  className?: string;
}

/** Email verification screen: 6 single-digit boxes with auto-advance, paste support, backspace navigation, auto-submit and a resend cooldown. */
export function AuthVerify({ email = "maya@acme.io", length = 6, onComplete, onResend, cooldown = 30, backHref = "#login", className }: AuthVerifyProps) {
  const id = useId();
  const [digits, setDigits] = useState<string[]>(() => Array(length).fill(""));
  const [status, setStatus] = useState<"idle" | "checking" | "error" | "ok">("idle");
  const [left, setLeft] = useState(cooldown);
  const refs = useRef<(HTMLInputElement | null)[]>([]);

  useEffect(() => {
    if (left <= 0) return;
    const t = window.setTimeout(() => setLeft((l) => l - 1), 1000);
    return () => window.clearTimeout(t);
  }, [left]);

  const commit = async (next: string[]) => {
    setDigits(next);
    if (next.every(Boolean)) {
      setStatus("checking");
      try {
        await onComplete?.(next.join(""));
        setStatus("ok");
      } catch {
        setStatus("error");
        setDigits(Array(length).fill(""));
        refs.current[0]?.focus();
      }
    } else if (status === "error") setStatus("idle");
  };

  const onChange = (i: number, v: string) => {
    const d = v.replace(/\D/g, "").slice(-1);
    const next = [...digits];
    next[i] = d;
    if (d && i < length - 1) refs.current[i + 1]?.focus();
    void commit(next);
  };

  const onKey = (i: number, e: KeyboardEvent<HTMLInputElement>) => {
    if (e.key === "Backspace" && !digits[i] && i > 0) refs.current[i - 1]?.focus();
    if (e.key === "ArrowLeft" && i > 0) refs.current[i - 1]?.focus();
    if (e.key === "ArrowRight" && i < length - 1) refs.current[i + 1]?.focus();
  };

  const onPaste = (e: ClipboardEvent<HTMLInputElement>) => {
    const text = e.clipboardData.getData("text").replace(/\D/g, "").slice(0, length);
    if (!text) return;
    e.preventDefault();
    const next = Array.from({ length }, (_, i) => text[i] ?? "");
    refs.current[Math.min(text.length, length - 1)]?.focus();
    void commit(next);
  };

  return (
    <div className={cn("grid min-h-dvh place-items-center bg-da-bg px-4 py-12 text-da-fg", className)}>
      <main className="w-full max-w-sm text-center">
        <span aria-hidden className="mx-auto grid size-12 place-items-center rounded-full bg-da-accent text-da-accent-fg">
          <MailCheck className="size-5" />
        </span>
        <h1 className="mt-5 text-xl font-semibold tracking-da-display">Check your email</h1>
        <p className="mt-2 text-sm text-da-muted-fg">
          We sent a {length}-digit code to <span className="font-medium text-da-fg">{email}</span>. It expires in 10 minutes.
        </p>
        <fieldset className="mt-8" aria-describedby={`${id}-status`}>
          <legend className="sr-only">Verification code</legend>
          <div className="flex justify-center gap-2">
            {digits.map((d, i) => (
              <input
                key={i}
                ref={(el) => {
                  refs.current[i] = el;
                }}
                value={d}
                onChange={(e) => onChange(i, e.target.value)}
                onKeyDown={(e) => onKey(i, e)}
                onPaste={onPaste}
                onFocus={(e) => e.currentTarget.select()}
                inputMode="numeric"
                autoComplete={i === 0 ? "one-time-code" : "off"}
                aria-label={`Digit ${i + 1} of ${length}`}
                aria-invalid={status === "error"}
                disabled={status === "checking" || status === "ok"}
                className={cn(
                  "da-focus da-transition size-11 rounded-da-md border bg-da-input text-center font-da-mono text-lg font-medium sm:size-12",
                  i === length / 2 && "ml-2",
                  status === "error" ? "border-da-danger" : status === "ok" ? "border-da-success" : "border-da-border focus:border-da-primary",
                )}
              />
            ))}
          </div>
        </fieldset>
        <p
          id={`${id}-status`}
          aria-live="polite"
          className={cn("mt-4 min-h-5 text-[13px]", status === "error" ? "text-da-danger" : status === "ok" ? "text-da-success" : "text-da-muted-fg")}
        >
          {status === "checking" ? "Verifying…" : status === "error" ? "That code didn’t work. Try again." : status === "ok" ? "Verified — redirecting…" : ""}
        </p>
        <p className="mt-6 text-[13px] text-da-muted-fg">
          Didn’t get it?{" "}
          <button
            type="button"
            disabled={left > 0}
            onClick={() => {
              onResend?.();
              setLeft(cooldown);
            }}
            className="da-focus rounded-da-sm font-medium text-da-fg hover:underline disabled:font-normal disabled:text-da-muted-fg disabled:no-underline"
          >
            {left > 0 ? `Resend in ${left}s` : "Resend code"}
          </button>
        </p>
        <a href={backHref} className="da-focus mt-8 inline-block rounded-da-sm text-[13px] text-da-muted-fg hover:text-da-fg">
          ← Use a different email
        </a>
      </main>
    </div>
  );
}

export default AuthVerify;

modules/minimal/layout/auth-verify/index.tsx

Props

PropTypeDefaultDescription
emailstring—Address shown.
lengthnumber6Digits.
onComplete(code: string) => void | Promise<void>—Throw to reject the code.
onResend() => void—Resend handler.
cooldownnumber30Seconds before resend.
backHrefstring—Back link.
classNamestring—Classes.

Other auth screen variants in Minimal

Auth screen in other art directions

Auth Card

Centered login card on a dotted paper background: tilted wordmark sticker, ink title band, GitHub button, email + password with forgot link, error slot and a big pressable yellow submit.

BrutalistAuth screen

Auth Magic Link

Passwordless login split screen: blue product panel with staggered pipeline cards (desktop), huge uppercase headline, single email field and yellow send button, then a 'Check your inbox' state with open-mail and retry actions.

BrutalistAuth screen

Auth Screen

Split sign-in / sign-up page: form column with GitHub & Google buttons, email + password (show/hide), remember-me, error slot and pending state; yellow grid panel with a big customer quote on desktop.

BrutalistAuth screen

Auth Signup Steps

Three-step signup wizard: ruled step tabs (done in ink, current in yellow) fused to a card with account fields, team size and use-case tile choices, Back/Continue and a success state.

BrutalistAuth screen

Auth Floating

Sign-up screen: centered glass card (Google button, divider, email magic-link form with success state) surrounded on desktop by floating, bobbing glass preview cards and a gradient orb.

GlassAuth screen

Auth Onboarding

Three-step onboarding glass card: workspace name with URL preview, role radio chips, calendar connection buttons; gradient progress bar, back/continue and a finish screen.

GlassAuth screen

Auth Passkey

Passkey sign-in glass card: glowing gradient fingerprint orb, account email, ‘Sign in with passkey’ with waiting / success / error states and email-link or password fallbacks.

GlassAuth screen

Auth Screen

Centered 40px-blur glass panel over the mesh and two soft orbs: gradient logo, Google/Microsoft buttons, email + password (show/hide), forgot link, error slot, gradient pill submit. Sign-in and sign-up modes.

GlassAuth screen

Auth Centered

Minimal centered sign-in with lots of air: logo, small title, two hairline-boxed fields stacked edge to edge, ink button, “or continue with” text links and a mono legal line at the very bottom.

Mono CleanAuth screen

Auth Magic

Passwordless: a huge “Enter your email” prompt with a single oversized underline input and ↵ button; after submit, a large confirmation with the address and a mono resend link.

Mono CleanAuth screen

Auth Screen

Split sign-in: the left half is an ink panel with a large statement and mono footer; the right half holds a minimal underline form (email, password), an ink button and text links. Panel hides on mobile.

Mono CleanAuth screen

Auth Steps

Three-step sign-up with an index header “01 / 03 — Your account” and segmented hairline progress; underline fields per step, Back text link and ink Continue; final step shows the site address preview.

Mono CleanAuth screen

Auth Screen

Centered sign-in card on a surface-2 page: logo, Google + SSO buttons, “or” divider, email/password (show/hide toggle, forgot link), remember me, blue submit, sign-up link and legal footer.

Neo CorporateAuth screen

Auth Split

Split sign-up page: form on the left (name, work email, company, password with live strength checklist), blue gradient panel on the right with benefits, a customer quote and compliance badges (panel hidden below lg).

Neo CorporateAuth screen

Auth Sso

Enterprise SSO sign-in: email-first step that detects the domain; SSO domains show the org + identity provider and a “Continue with Okta” button, others fall back to a password field.

Neo CorporateAuth screen

Auth Verify

Two-factor verification screen: shield icon, 6 separate digit boxes (auto-advance, backspace, paste support), error/success states, resend with 30s countdown and “use a recovery code” link.

Neo CorporateAuth screen

Auth Magic

Passwordless sign-in: one rounded email field and “Send me a link”, then a gentle sent state with an open-envelope in a sage circle, the address, resend and change-email links.

Organic SoftAuth screen

Auth Onboarding

Post-signup onboarding: two gentle steps (industry as pill radio cards, goals as check cards) with a leaf progress bar, back/continue pills and a warm “all set” finish.

Organic SoftAuth screen

Auth Screen

Centered sign-in on cream with two soft blobs behind a rounded card: serif welcome, filled inputs, password reveal, sage pill submit, Google alternative and a sign-up link.

Organic SoftAuth screen

Auth Split

Split sign-up: form on cream (name, email, company, team-size pills) and an arch-topped landscape illustration panel with sun and hills plus a quote card (hidden below lg).

Organic SoftAuth screen

Auth Magic

“Check your inbox” screen: flat envelope with a gently bobbing letter, email in bold, Gmail/Outlook shortcut pills, resend with countdown and change-email link.

Soft FlatAuth screen

Auth Screen

Centered friendly sign-in: big rounded white card among pastel shapes, shape logo, Google button, rounded divider, soft email/password fields with reveal, error alert and periwinkle pill.

Soft FlatAuth screen

Auth Split

Sign-up split: lavender panel with a flat illustration of tilted task cards and perk list on large screens, roomy name + email form with a success message on the other side.

Soft FlatAuth screen

Auth Welcome

First-run profile setup: big live avatar preview, grid of pastel emoji avatars (native radios), display-name field with preview chip and a “Let’s go” button enabled once named.

Soft FlatAuth screen