Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Authentication

2 examples. Resize any preview to see it at phone and tablet widths.

Auth Flow

Free

Sign in, two-factor code and password reset in one card: inline validation, a shake and selected field on a wrong password, caps-lock warning, attempt lockout with countdown, paste-aware OTP input and resend timer.

Magic Link Sign-in

Free

A passwordless sign-in card that validates the email and moves to a confirmation step without resizing.

Hide code
components/blocks/signin-magic.tsx
"use client";

import { useId, useState } from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { ArrowLeft, MailCheck } from "lucide-react";

export default function SigninMagic() {
  const id = useId();
  const reduce = useReducedMotion();
  const [email, setEmail] = useState("");
  const [error, setError] = useState("");
  const [step, setStep] = useState<"form" | "sending" | "sent">("form");

  function submit(event: React.FormEvent) {
    event.preventDefault();
    if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) return setError("Enter an email address like name@company.com.");
    setError("");
    setStep("sending");
    // Replace with your own request.
    setTimeout(() => setStep("sent"), 900);
  }

  const panel = {
    initial: reduce ? { opacity: 0 } : { opacity: 0, y: 12, filter: "blur(4px)" },
    animate: { opacity: 1, y: 0, filter: "blur(0px)" },
    exit: reduce ? { opacity: 0 } : { opacity: 0, y: -12, filter: "blur(4px)" },
    transition: { duration: 0.22, ease: [0.215, 0.61, 0.355, 1] as const },
  };

  return (
    <section className="grid w-full place-items-center px-4 py-12 sm:py-20">
      {/* Both steps share one fixed-height card, so moving between them never resizes it. */}
      <div className="relative h-[25rem] w-full max-w-sm overflow-hidden rounded-2xl border border-border bg-card p-7">
        <AnimatePresence mode="wait" initial={false}>
          {step === "sent" ? (
            <motion.div key="sent" {...panel} className="flex h-full flex-col">
              <span className="grid size-11 place-items-center rounded-full bg-foreground text-background"><MailCheck className="size-5" aria-hidden /></span>
              <h1 tabIndex={-1} ref={(node) => node?.focus()} className="mt-5 text-2xl font-semibold tracking-tight outline-none">Check your inbox</h1>
              <p className="mt-2 text-pretty text-sm leading-relaxed text-muted-foreground">We sent a sign-in link to <span className="font-medium text-foreground">{email}</span>. It works once and expires in 15 minutes.</p>
              <button type="button" onClick={() => setStep("form")} className="mt-auto inline-flex h-10 items-center gap-2 self-start rounded-lg px-2 text-sm font-medium text-muted-foreground outline-none transition-colors duration-150 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring">
                <ArrowLeft className="size-4" aria-hidden /> Use a different email
              </button>
            </motion.div>
          ) : (
            <motion.form key="form" {...panel} onSubmit={submit} noValidate className="flex h-full flex-col">
              <h1 className="text-2xl font-semibold tracking-tight">Sign in to Relay</h1>
              <p className="mt-2 text-sm text-muted-foreground">No password. We email you a link.</p>
              <label htmlFor={id} className="mt-7 text-sm font-medium">Email</label>
              <input id={id} type="email" inputMode="email" autoComplete="email" value={email} onChange={(e) => { setEmail(e.target.value); setError(""); }} aria-invalid={error ? true : undefined} aria-describedby={`${id}-help`} placeholder="you@company.com" className="mt-1.5 h-11 w-full rounded-lg border border-border bg-background px-3.5 text-base outline-none transition-[border-color,box-shadow] duration-150 placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-4 focus-visible:ring-ring/20 aria-invalid:border-destructive" />
              <p id={`${id}-help`} role={error ? "alert" : undefined} className="mt-1.5 min-h-5 text-sm text-destructive">{error}</p>
              <button type="submit" disabled={step === "sending"} className="mt-2 h-11 rounded-lg bg-foreground text-sm font-medium text-background outline-none transition-[background-color,scale,opacity] duration-150 hover:bg-foreground/90 enabled:active:scale-[0.96] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card disabled:opacity-70 motion-reduce:transition-none">
                {step === "sending" ? "Sending link" : "Email me a link"}
              </button>
              <p className="mt-auto text-xs leading-relaxed text-muted-foreground">By continuing you agree to the <a href="#terms" className="rounded-sm underline underline-offset-2 outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring">terms</a> and <a href="#privacy" className="rounded-sm underline underline-offset-2 outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring">privacy policy</a>.</p>
            </motion.form>
          )}
        </AnimatePresence>
      </div>
    </section>
  );
}