Pages
Auth

Sign Up Page

A sign up page for React with GitHub and Google buttons, inline validation, a show and hide password toggle, a password strength meter, a terms checkbox, loading and success states, and a side panel with perks and a quote.

sign-up-page.preview

Create your account

Start building in a minute. No credit card required.

or

Already have an account? Log in

Install

Copies the source into components/blocks/signup-page.tsx and installs what it needs.

$ pnpm dlx shadcn@latest add https://makeui.xyz/r/signup-page.json

Usage

app/page.tsx
import { SignupPage } from "@/components/blocks/signup-page"

export default function Page() {
  return (
    <SignupPage
      title="Create your account"
      loginHref="/login"
      termsHref="/terms"
      privacyHref="/privacy"
      onSubmit={async ({ name, email, password }) => {
        const res = await fetch("/api/signup", {
          method: "POST",
          body: JSON.stringify({ name, email, password }),
        })
        if (!res.ok) throw new Error("Couldn't create your account.")
      }}
      onOAuth={(provider) => {
        window.location.href = `/api/auth/${provider}`
      }}
    />
  )
}

Source

Prefer to copy by hand? It's one file. Requires motion and the shadcn cn helper.

components/blocks/signup-page.tsx
"use client"

import { useEffect, useId, useState } from "react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { Check, Eye, EyeOff, Loader2 } from "lucide-react"
import { cn } from "@/lib/utils"

/* ───────────── types ───────────── */

type ThemeName = "light" | "dark"
type Values = { name: string; email: string; password: string }
type Provider = "github" | "google"

type Props = {
  title?: string
  subtitle?: string
  /** Called with the form values. Throw to show an error. Leave out to simulate a request. */
  onSubmit?: (values: Values) => Promise<void> | void
  onOAuth?: (provider: Provider) => void
  loginHref?: string
  termsHref?: string
  privacyHref?: string
  quote?: string
  quoteBy?: string
  perks?: string[]
  /** Pin a theme. Leave out to follow the site (.dark on <html>). */
  theme?: ThemeName
  className?: string
}

/* ───────────── theme + helpers ───────────── */

const themes: Record<ThemeName, Record<string, string>> = {
  light: { "--su-bg": "#fdfdfc", "--su-fg": "#1c1b19", "--su-body": "#5f5d58", "--su-muted": "#8b8983", "--su-line": "rgb(28 27 25 / 0.12)", "--su-card": "#f2f2f0", "--su-accent": "#2f8f5b" },
  dark: { "--su-bg": "#0a0a0a", "--su-fg": "#f5f5f4", "--su-body": "#a8a6a0", "--su-muted": "#7d7b75", "--su-line": "rgb(245 245 244 / 0.12)", "--su-card": "#161615", "--su-accent": "#4ade80" },
}

function useHtmlDark() {
  const [dark, setDark] = useState(false)
  useEffect(() => {
    const el = document.documentElement
    const read = () => setDark(el.classList.contains("dark"))
    read()
    const mo = new MutationObserver(read)
    mo.observe(el, { attributes: true, attributeFilter: ["class"] })
    return () => mo.disconnect()
  }, [])
  return dark
}

const errorsFor = (v: Values): Record<keyof Values, string> => ({
  name: v.name.trim().length < 2 ? "Enter your name." : "",
  email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v.email) ? "" : "Enter a valid email address.",
  password: v.password.length < 8 ? "Use at least 8 characters." : "",
})

const strengthLabels = ["Too short", "Weak", "Fair", "Good", "Strong"]
function strength(p: string) {
  let s = 0
  if (p.length >= 8) s++
  if (/[a-z]/.test(p) && /[A-Z]/.test(p)) s++
  if (/\d/.test(p)) s++
  if (/[^A-Za-z0-9]/.test(p)) s++
  return p.length < 8 ? Math.min(s, 1) : s
}

const GithubIcon = () => (
  <svg viewBox="0 0 24 24" className="size-4" fill="currentColor" aria-hidden>
    <path d="M12 .5a11.5 11.5 0 0 0-3.64 22.41c.58.1.79-.25.79-.56v-2c-3.2.7-3.88-1.37-3.88-1.37-.52-1.33-1.28-1.69-1.28-1.69-1.04-.71.08-.7.08-.7 1.15.08 1.76 1.19 1.76 1.19 1.03 1.76 2.7 1.25 3.35.96.1-.75.4-1.25.73-1.54-2.55-.29-5.24-1.28-5.24-5.69 0-1.26.45-2.28 1.19-3.08-.12-.29-.52-1.46.11-3.05 0 0 .97-.31 3.17 1.18a10.9 10.9 0 0 1 5.78 0c2.2-1.49 3.17-1.18 3.17-1.18.63 1.59.23 2.76.11 3.05.74.8 1.19 1.82 1.19 3.08 0 4.42-2.69 5.39-5.25 5.68.41.36.78 1.06.78 2.14v3.17c0 .31.21.67.8.56A11.5 11.5 0 0 0 12 .5Z" />
  </svg>
)

const GoogleIcon = () => (
  <svg viewBox="0 0 48 48" className="size-4" aria-hidden>
    <path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z" />
    <path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z" />
    <path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z" />
    <path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z" />
  </svg>
)

const inputCls = (bad: boolean) =>
  cn(
    "h-10 w-full rounded-xl border bg-transparent px-3 text-sm text-(--su-fg) outline-none transition-colors placeholder:text-(--su-muted) focus:border-(--su-fg)/40 focus-visible:ring-2 focus-visible:ring-(--su-muted)/30",
    bad ? "border-rose-500/60" : "border-(--su-line)"
  )

function FieldError({ message }: { message?: string }) {
  return (
    <AnimatePresence initial={false}>
      {message && (
        <motion.p
          initial={{ opacity: 0, height: 0 }}
          animate={{ opacity: 1, height: "auto" }}
          exit={{ opacity: 0, height: 0 }}
          transition={{ duration: 0.15 }}
          className="overflow-hidden pt-1.5 text-xs text-rose-500"
        >
          {message}
        </motion.p>
      )}
    </AnimatePresence>
  )
}

const oauthBtn = "inline-flex h-10 items-center justify-center gap-2 rounded-xl border border-(--su-line) text-sm text-(--su-fg) outline-none transition-colors hover:bg-(--su-card) focus-visible:ring-2 focus-visible:ring-(--su-muted)/40"

/* ───────────── page ───────────── */

export function SignupPage({
  title = "Create your account",
  subtitle = "Start building in a minute. No credit card required.",
  onSubmit,
  onOAuth,
  loginHref = "#",
  termsHref = "#",
  privacyHref = "#",
  quote = "Set up in minutes, and it just feels right. Every small detail is in the right place.",
  quoteBy = "Alex Morgan, Full Stack Developer",
  perks = ["Free forever for personal projects", "Unlimited projects and components", "Cancel anytime, keep your data"],
  theme,
  className,
}: Props) {
  const reduce = useReducedMotion()
  const siteDark = useHtmlDark()
  const uid = useId()

  const [values, setValues] = useState<Values>({ name: "", email: "", password: "" })
  const [touched, setTouched] = useState<Partial<Record<keyof Values, boolean>>>({})
  const [submitted, setSubmitted] = useState(false)
  const [show, setShow] = useState(false)
  const [agree, setAgree] = useState(false)
  const [status, setStatus] = useState<"idle" | "loading" | "done">("idle")
  const [formError, setFormError] = useState("")

  const current: ThemeName = theme ?? (siteDark ? "dark" : "light")
  const vars = themes[current] as React.CSSProperties
  const errors = errorsFor(values)
  const shown = (k: keyof Values) => ((touched[k] || submitted) && errors[k]) || ""
  const change = (k: keyof Values) => (e: React.ChangeEvent<HTMLInputElement>) => setValues((v) => ({ ...v, [k]: e.target.value }))
  const blur = (k: keyof Values) => () => setTouched((t) => ({ ...t, [k]: true }))

  const score = strength(values.password)
  const meterColor = score <= 1 ? "#f43f5e" : score === 2 ? "#f59e0b" : "var(--su-accent)"

  async function submit(e: React.FormEvent) {
    e.preventDefault()
    setSubmitted(true)
    setFormError("")
    if (Object.values(errors).some(Boolean) || !agree) return
    setStatus("loading")
    try {
      if (onSubmit) await onSubmit(values)
      else await new Promise((r) => setTimeout(r, 900))
      setStatus("done")
    } catch {
      setFormError("Something went wrong. Please try again.")
      setStatus("idle")
    }
  }

  function reset() {
    setValues({ name: "", email: "", password: "" })
    setTouched({})
    setSubmitted(false)
    setAgree(false)
    setStatus("idle")
  }

  return (
    <div className="@container">
      <div style={vars} className={cn("bg-(--su-bg) text-(--su-body) transition-colors duration-500", className)}>
        <div className="mx-auto grid min-h-[40rem] max-w-4xl gap-6 px-6 py-10 @3xl:grid-cols-2">
          {/* form side */}
          <div className="flex items-center justify-center @3xl:px-6">
            <div className="w-full max-w-sm">
              <AnimatePresence mode="wait" initial={false}>
                {status === "done" ? (
                  <motion.div
                    key="done"
                    initial={reduce ? false : { opacity: 0, y: 8 }}
                    animate={{ opacity: 1, y: 0 }}
                    exit={{ opacity: 0 }}
                    transition={{ duration: 0.2 }}
                    className="text-center"
                  >
                    <motion.span
                      initial={reduce ? false : { scale: 0.5, opacity: 0 }}
                      animate={{ scale: 1, opacity: 1 }}
                      transition={{ type: "spring", stiffness: 420, damping: 22 }}
                      className="mx-auto grid size-12 place-items-center rounded-full bg-(--su-card) text-(--su-accent)"
                    >
                      <Check className="size-5" />
                    </motion.span>
                    <h1 className="mt-5 text-base font-medium text-(--su-fg)">Check your inbox</h1>
                    <p className="mt-1.5 text-sm">
                      We sent a confirmation link to <span className="text-(--su-fg)">{values.email}</span>.
                    </p>
                    <button type="button" onClick={reset} className="mt-6 text-sm text-(--su-muted) underline underline-offset-4 transition-colors hover:text-(--su-fg)">
                      Use a different email
                    </button>
                  </motion.div>
                ) : (
                  <motion.div key="form" initial={false} exit={{ opacity: 0 }} transition={{ duration: 0.15 }}>
                    <h1 className="text-lg font-medium text-(--su-fg)">{title}</h1>
                    <p className="mt-1 text-sm text-(--su-muted)">{subtitle}</p>

                    <div className="mt-6 grid grid-cols-2 gap-2">
                      <button type="button" onClick={() => onOAuth?.("github")} className={oauthBtn}>
                        <GithubIcon /> GitHub
                      </button>
                      <button type="button" onClick={() => onOAuth?.("google")} className={oauthBtn}>
                        <GoogleIcon /> Google
                      </button>
                    </div>

                    <div className="my-5 flex items-center gap-3 text-xs text-(--su-muted)">
                      <span className="h-px flex-1 bg-(--su-line)" />
                      or
                      <span className="h-px flex-1 bg-(--su-line)" />
                    </div>

                    <form onSubmit={submit} noValidate className="space-y-4">
                      <div>
                        <label htmlFor={`${uid}-name`} className="mb-1.5 block text-sm text-(--su-fg)">Name</label>
                        <input id={`${uid}-name`} name="name" autoComplete="name" placeholder="Alex Morgan" value={values.name} onChange={change("name")} onBlur={blur("name")} aria-invalid={!!shown("name")} className={inputCls(!!shown("name"))} />
                        <FieldError message={shown("name")} />
                      </div>

                      <div>
                        <label htmlFor={`${uid}-email`} className="mb-1.5 block text-sm text-(--su-fg)">Email</label>
                        <input id={`${uid}-email`} name="email" type="email" autoComplete="email" placeholder="you@example.com" value={values.email} onChange={change("email")} onBlur={blur("email")} aria-invalid={!!shown("email")} className={inputCls(!!shown("email"))} />
                        <FieldError message={shown("email")} />
                      </div>

                      <div>
                        <label htmlFor={`${uid}-password`} className="mb-1.5 block text-sm text-(--su-fg)">Password</label>
                        <div className="relative">
                          <input
                            id={`${uid}-password`}
                            name="password"
                            type={show ? "text" : "password"}
                            autoComplete="new-password"
                            placeholder="At least 8 characters"
                            value={values.password}
                            onChange={change("password")}
                            onBlur={blur("password")}
                            aria-invalid={!!shown("password")}
                            className={cn(inputCls(!!shown("password")), "pr-10")}
                          />
                          <button
                            type="button"
                            onClick={() => setShow((s) => !s)}
                            aria-label={show ? "Hide password" : "Show password"}
                            className="absolute right-1.5 top-1/2 grid size-7 -translate-y-1/2 place-items-center rounded-lg text-(--su-muted) outline-none transition-colors hover:text-(--su-fg) focus-visible:ring-2 focus-visible:ring-(--su-muted)/40"
                          >
                            {show ? <EyeOff className="size-4" /> : <Eye className="size-4" />}
                          </button>
                        </div>
                        <FieldError message={shown("password")} />

                        {values.password && (
                          <div className="mt-2.5" aria-live="polite">
                            <div className="flex gap-1">
                              {[1, 2, 3, 4].map((i) => (
                                <span key={i} className="h-1 flex-1 rounded-full transition-colors duration-300" style={{ background: i <= score ? meterColor : "var(--su-card)" }} />
                              ))}
                            </div>
                            <p className="mt-1.5 text-xs text-(--su-muted)">{strengthLabels[score]}</p>
                          </div>
                        )}
                      </div>

                      <div>
                        <label className="flex cursor-pointer items-start gap-2.5 text-sm">
                          <input type="checkbox" checked={agree} onChange={(e) => setAgree(e.target.checked)} className="peer sr-only" />
                          <span className="mt-0.5 grid size-4 shrink-0 place-items-center rounded-[5px] border border-(--su-line) text-(--su-bg) transition-colors peer-checked:border-transparent peer-checked:bg-(--su-fg) peer-focus-visible:ring-2 peer-focus-visible:ring-(--su-muted)/40 [&>svg]:opacity-0 peer-checked:[&>svg]:opacity-100">
                            <Check className="size-3" strokeWidth={3} />
                          </span>
                          <span>
                            I agree to the{" "}
                            <a href={termsHref} className="text-(--su-fg) underline underline-offset-4">Terms</a> and{" "}
                            <a href={privacyHref} className="text-(--su-fg) underline underline-offset-4">Privacy Policy</a>.
                          </span>
                        </label>
                        <FieldError message={submitted && !agree ? "Please accept the terms to continue." : ""} />
                      </div>

                      {formError && <p role="alert" className="text-sm text-rose-500">{formError}</p>}

                      <button
                        type="submit"
                        disabled={status === "loading"}
                        className="inline-flex h-10 w-full items-center justify-center gap-2 rounded-xl bg-(--su-fg) text-sm text-(--su-bg) outline-none transition-opacity hover:opacity-85 focus-visible:ring-2 focus-visible:ring-(--su-muted)/60 focus-visible:ring-offset-2 focus-visible:ring-offset-(--su-bg) disabled:opacity-60"
                      >
                        {status === "loading" ? <Loader2 className="size-4 animate-spin" /> : null}
                        {status === "loading" ? "Creating account" : "Create account"}
                      </button>
                    </form>

                    <p className="mt-6 text-center text-sm text-(--su-muted)">
                      Already have an account?{" "}
                      <a href={loginHref} className="text-(--su-fg) underline underline-offset-4">Log in</a>
                    </p>
                  </motion.div>
                )}
              </AnimatePresence>
            </div>
          </div>

          {/* side panel, only on wider containers */}
          <aside
            className="hidden flex-col justify-between rounded-3xl p-8 @3xl:flex"
            style={{ background: "linear-gradient(135deg, color-mix(in oklab, var(--su-accent) 18%, var(--su-bg)), color-mix(in oklab, var(--su-accent) 5%, var(--su-bg)))" }}
          >
            <ul className="space-y-3 text-sm">
              {perks.map((p) => (
                <li key={p} className="flex items-center gap-2.5 text-(--su-fg)">
                  <span className="grid size-5 place-items-center rounded-full bg-(--su-bg)/70 text-(--su-accent)">
                    <Check className="size-3" strokeWidth={3} />
                  </span>
                  {p}
                </li>
              ))}
            </ul>
            <figure>
              <blockquote className="text-lg leading-snug text-(--su-fg)">“{quote}”</blockquote>
              <figcaption className="mt-4 text-sm text-(--su-muted)">{quoteBy}</figcaption>
            </figure>
          </aside>
        </div>
      </div>
    </div>
  )
}