Login pages
Sign-in screens that check each field as you leave it and show what happens next. A centered card, a split page on the theme's band, providers first, a magic link and a six-digit code.
5 blocks below, each one file and one command. They wear whichever DressCode theme you install, in light and dark.
Centered card
Email and password with a show toggle, remember me, a forgot-password link, Google and GitHub, and a spinner, then a signed-in state.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/login-card.json"use client"
// Login, card: a centered sign-in card on a soft surface. Email and a password with a show/hide toggle,
// remember me, a forgot-password link, Google and GitHub, and a way to sign up. Each field is checked
// when it loses focus and again on submit; errors are tied to their field. Submitting shows a spinner,
// then a signed-in state. Wire onSubmit and the two provider buttons to your own auth.
import { ArrowRight, Check, Eye, EyeOff, LoaderCircle } from "lucide-react"
import { type FocusEvent, type FormEvent, type ReactNode, useEffect, useId, useRef, useState } from "react"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
const link = "rounded-[2px] font-medium text-[color:var(--dc-accent)] outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50"
// Leaving a field for a button in the same form (submit, the password toggle) skips the blur check: an
// error appearing above that button would move it out from under the click. Submit checks everything.
const toButton = (e: FocusEvent<HTMLInputElement>) => e.relatedTarget instanceof HTMLButtonElement && e.relatedTarget.form === e.currentTarget.form
type Field = "email" | "password"
const check = (f: Field, v: string) =>
f === "email" ? (!v.trim() ? "Enter your email." : EMAIL.test(v.trim()) ? "" : "That doesn't look like an email address.") : v ? "" : "Enter your password."
function Logo() {
return (
<span className="inline-flex items-center gap-2 text-[18px] font-bold tracking-[-0.02em]">
<svg width="22" height="22" viewBox="0 0 22 22" aria-hidden="true">
<circle cx="11" cy="11" r="8.5" fill="none" stroke="currentColor" strokeWidth="3" />
<circle cx="16.5" cy="5.5" r="3" fill="var(--dc-accent)" />
</svg>
<span className="dc-h">Orbit</span>
</span>
)
}
function GoogleMark() {
return (
<svg viewBox="0 0 24 24" className="size-4" aria-hidden="true">
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.27-4.74 3.27-8.1z" />
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84A11 11 0 0 0 12 23z" />
<path fill="#FBBC05" d="M5.84 14.1a6.6 6.6 0 0 1 0-4.2V7.06H2.18a11 11 0 0 0 0 9.88l3.66-2.84z" />
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15A10.96 10.96 0 0 0 12 1 11 11 0 0 0 2.18 7.06l3.66 2.84C6.71 7.31 9.14 5.38 12 5.38z" />
</svg>
)
}
function GitHubMark() {
return (
<svg viewBox="0 0 16 16" className="size-4" fill="currentColor" aria-hidden="true">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z" />
</svg>
)
}
function FieldRow({ id, label, error, aside, children }: { id: string; label: string; error: string; aside?: ReactNode; children: ReactNode }) {
return (
<div className="grid gap-1.5">
<div className="flex min-h-5 items-center justify-between gap-3">
<Label htmlFor={id} className="text-[13px]">
{label}
</Label>
{aside}
</div>
{children}
{error ? (
<p id={`${id}-error`} className="text-[13px] text-destructive">
{error}
</p>
) : null}
</div>
)
}
export default function LoginCard() {
const id = useId()
const [values, setValues] = useState({ email: "", password: "" })
const [errors, setErrors] = useState({ email: "", password: "" })
const [show, setShow] = useState(false)
const [remember, setRemember] = useState(true)
const [busy, setBusy] = useState<"" | "email" | "Google" | "GitHub">("")
const [done, setDone] = useState<"" | "email" | "Google" | "GitHub">("")
const timer = useRef<ReturnType<typeof setTimeout>>(undefined)
const doneTitle = useRef<HTMLHeadingElement>(null)
useEffect(() => () => clearTimeout(timer.current), [])
useEffect(() => {
if (done) doneTitle.current?.focus()
}, [done])
const set = (f: Field, v: string) => {
setValues((s) => ({ ...s, [f]: v }))
if (errors[f]) setErrors((s) => ({ ...s, [f]: check(f, v) }))
}
const blur = (f: Field, e: FocusEvent<HTMLInputElement>) => {
if (toButton(e)) return
if (values[f]) setErrors((s) => ({ ...s, [f]: check(f, values[f]) }))
}
const finish = (how: "email" | "Google" | "GitHub") => {
setBusy(how)
// Replace the timeout with your sign-in call (or the redirect to the provider).
timer.current = setTimeout(() => {
setBusy("")
setDone(how)
}, 1200)
}
const onSubmit = (e: FormEvent) => {
e.preventDefault()
const next = { email: check("email", values.email), password: check("password", values.password) }
setErrors(next)
const first = (["email", "password"] as const).find((f) => next[f])
if (first) document.getElementById(`${id}-${first}`)?.focus()
else finish("email")
}
return (
<section aria-labelledby={`${id}-title`} className="flex min-h-[760px] flex-col items-center justify-center bg-muted px-5 py-16 sm:px-8">
<a href="#home" className="rounded-[2px] outline-none focus-visible:ring-3 focus-visible:ring-ring/50" aria-label="Orbit home">
<Logo />
</a>
<div className="dc-card mt-8 w-full max-w-[420px] p-6 sm:p-8">
{done ? (
<div role="status" className="py-4 text-center">
<span className="dc-icon size-12">
<Check className="size-5" aria-hidden="true" />
</span>
<h1 id={`${id}-title`} ref={doneTitle} tabIndex={-1} className="dc-h mt-5 text-[24px] leading-tight outline-none">
You’re signed in
</h1>
<p className="mx-auto mt-2 max-w-[300px] text-[15px] leading-relaxed text-muted-foreground">
{done === "email" ? (
<>
Welcome back, <span className="font-medium [overflow-wrap:anywhere] text-foreground">{values.email.trim()}</span>.
</>
) : (
<>Welcome back. You signed in with {done}.</>
)}{" "}
{remember || done !== "email" ? "This device stays signed in for 30 days." : "We'll sign you out when you close the browser."}
</p>
<Button className="mt-6 h-10 px-5 text-[15px] font-semibold" nativeButton={false} render={<a href="#invoices" />}>
Go to your invoices <ArrowRight className="size-4" aria-hidden="true" />
</Button>
</div>
) : (
<>
<h1 id={`${id}-title`} className="dc-h text-[26px] leading-tight">
Sign in to Orbit
</h1>
<p className="mt-1.5 text-[15px] text-pretty text-muted-foreground">Welcome back. See who has paid this week.</p>
<div className="mt-6 grid grid-cols-2 gap-2.5">
{(["Google", "GitHub"] as const).map((p) => (
<Button key={p} type="button" variant="outline" className="h-10 text-[14px] font-medium" disabled={!!busy} onClick={() => finish(p)}>
{busy === p ? <LoaderCircle className="size-4 animate-spin motion-reduce:animate-none" aria-hidden="true" /> : p === "Google" ? <GoogleMark /> : <GitHubMark />}
{p}
</Button>
))}
</div>
<div className="my-6 flex items-center gap-3 text-[13px] text-muted-foreground">
<span className="h-px flex-1 bg-border" aria-hidden="true" />
or with your email
<span className="h-px flex-1 bg-border" aria-hidden="true" />
</div>
<form noValidate onSubmit={onSubmit} className="grid gap-4">
<FieldRow id={`${id}-email`} label="Email" error={errors.email}>
<Input
id={`${id}-email`}
type="email"
autoComplete="email"
placeholder="you@studio.com"
value={values.email}
onChange={(e) => set("email", e.target.value)}
onBlur={(e) => blur("email", e)}
aria-invalid={errors.email ? true : undefined}
aria-describedby={errors.email ? `${id}-email-error` : undefined}
className="h-10"
/>
</FieldRow>
<FieldRow
id={`${id}-password`}
label="Password"
error={errors.password}
aside={
<a href="#forgot-password" className={`${link} text-[13px]`}>
Forgot password?
</a>
}
>
<div className="relative">
<Input
id={`${id}-password`}
type={show ? "text" : "password"}
autoComplete="current-password"
value={values.password}
onChange={(e) => set("password", e.target.value)}
onBlur={(e) => blur("password", e)}
aria-invalid={errors.password ? true : undefined}
aria-describedby={errors.password ? `${id}-password-error` : undefined}
className="h-10 pr-11"
/>
<button
type="button"
onClick={() => setShow((s) => !s)}
aria-label="Show password"
aria-pressed={show}
className="absolute inset-y-0 right-1 my-auto grid size-8 place-items-center rounded-[calc(var(--radius)-2px)] text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50"
>
{show ? <EyeOff className="size-4" aria-hidden="true" /> : <Eye className="size-4" aria-hidden="true" />}
</button>
</div>
</FieldRow>
<label className="flex w-fit items-center gap-2.5 text-[14px]">
<Checkbox checked={remember} onCheckedChange={(v) => setRemember(v === true)} />
Remember me for 30 days
</label>
<Button type="submit" className="mt-1 h-10 w-full text-[15px] font-semibold" disabled={!!busy}>
{busy === "email" ? <LoaderCircle className="size-4 animate-spin motion-reduce:animate-none" aria-hidden="true" /> : null}
{busy === "email" ? "Signing in…" : "Sign in"}
</Button>
<p className="sr-only" aria-live="polite">
{busy ? `Signing in${busy === "email" ? "" : ` with ${busy}`}…` : ""}
</p>
</form>
</>
)}
</div>
<p className="mt-6 text-[14px] text-muted-foreground">
New to Orbit?{" "}
<a href="#sign-up" className="rounded-[2px] font-semibold text-foreground outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50">
Create an account
</a>
</p>
</section>
)
}Split with the band
The form open on the page and, beside it on the theme's band, what Orbit does, two figures and a customer's words. The band steps aside on phones.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/login-split.json"use client"
// Login, split: the form on the left, open on the page; on the right the theme's band (dc-band switches
// the text to the band's own pair) with what Orbit does, two figures and a customer's words. On phones
// the band steps aside and the form is the page. Fields are checked when they lose focus and on
// submit. Wire onSubmit and the Google button to your own auth.
import { ArrowRight, Check, Eye, EyeOff, LoaderCircle } from "lucide-react"
import { type FocusEvent, type FormEvent, type ReactNode, useEffect, useId, useRef, useState } from "react"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
const focus = "rounded-[2px] outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
// Leaving a field for a button in the same form (submit, the password toggle) skips the blur check: an
// error appearing above that button would move it out from under the click. Submit checks everything.
const toButton = (e: FocusEvent<HTMLInputElement>) => e.relatedTarget instanceof HTMLButtonElement && e.relatedTarget.form === e.currentTarget.form
type Field = "email" | "password"
const check = (f: Field, v: string) =>
f === "email"
? !v.trim()
? "Enter the email you signed up with."
: EMAIL.test(v.trim())
? ""
: "That doesn't look like an email address."
: v
? ""
: "Enter your password."
function Logo() {
return (
<span className="inline-flex items-center gap-2 text-[18px] font-bold tracking-[-0.02em]">
<svg width="22" height="22" viewBox="0 0 22 22" aria-hidden="true">
<circle cx="11" cy="11" r="8.5" fill="none" stroke="currentColor" strokeWidth="3" />
<circle cx="16.5" cy="5.5" r="3" fill="var(--dc-accent)" />
</svg>
<span className="dc-h">Orbit</span>
</span>
)
}
function GoogleMark() {
return (
<svg viewBox="0 0 24 24" className="size-4" aria-hidden="true">
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.27-4.74 3.27-8.1z" />
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84A11 11 0 0 0 12 23z" />
<path fill="#FBBC05" d="M5.84 14.1a6.6 6.6 0 0 1 0-4.2V7.06H2.18a11 11 0 0 0 0 9.88l3.66-2.84z" />
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15A10.96 10.96 0 0 0 12 1 11 11 0 0 0 2.18 7.06l3.66 2.84C6.71 7.31 9.14 5.38 12 5.38z" />
</svg>
)
}
function FieldRow({ id, label, error, aside, children }: { id: string; label: string; error: string; aside?: ReactNode; children: ReactNode }) {
return (
<div className="grid gap-1.5">
<div className="flex min-h-5 items-center justify-between gap-3">
<Label htmlFor={id} className="text-[13px]">
{label}
</Label>
{aside}
</div>
{children}
{error ? (
<p id={`${id}-error`} className="text-[13px] text-destructive">
{error}
</p>
) : null}
</div>
)
}
function BandPanel() {
return (
<aside aria-label="Why studios use Orbit" className="dc-band m-3 hidden flex-col justify-between gap-10 overflow-hidden rounded-[var(--dc-radius-card)] p-10 lg:flex xl:p-12">
<div className="max-w-[480px]">
<p className="text-sm font-semibold opacity-80">Invoicing for freelancers and small studios</p>
<p className="dc-h mt-4 text-[34px] leading-[1.1] xl:text-[40px]">Send the invoice. Orbit chases it, politely, until it is paid.</p>
<dl className="mt-10 grid grid-cols-2 gap-6 border-t border-border pt-6">
<div>
<dt className="text-[14px] text-muted-foreground">Average time to get paid</dt>
<dd className="dc-num mt-1 text-[32px] font-semibold tracking-tight">11 days</dd>
</div>
<div>
<dt className="text-[14px] text-muted-foreground">Studios and freelancers</dt>
<dd className="dc-num mt-1 text-[32px] font-semibold tracking-tight">12,000</dd>
</div>
</dl>
</div>
<figure className="max-w-[480px] rounded-[calc(var(--radius)+4px)] border border-border bg-[color:color-mix(in_oklab,var(--dc-band-fg)_6%,transparent)] p-6">
<blockquote className="text-[17px] leading-relaxed">
“We stopped writing awkward follow-up emails. Orbit sends them in our tone, and clients just pay.”
</blockquote>
<figcaption className="mt-5 flex items-center gap-3 text-[14px]">
<span aria-hidden="true" className="grid size-9 place-items-center rounded-full bg-[color:color-mix(in_oklab,var(--dc-band-fg)_14%,transparent)] text-[12px] font-bold">
MO
</span>
<span>
<span className="block font-semibold">Maya Okafor</span>
<span className="block text-muted-foreground">Founder, Fernwood Studio</span>
</span>
</figcaption>
</figure>
</aside>
)
}
export default function LoginSplit() {
const id = useId()
const [values, setValues] = useState({ email: "", password: "" })
const [errors, setErrors] = useState({ email: "", password: "" })
const [show, setShow] = useState(false)
const [busy, setBusy] = useState<"" | "email" | "google">("")
const [done, setDone] = useState<"" | "email" | "google">("")
const timer = useRef<ReturnType<typeof setTimeout>>(undefined)
const doneTitle = useRef<HTMLHeadingElement>(null)
useEffect(() => () => clearTimeout(timer.current), [])
useEffect(() => {
if (done) doneTitle.current?.focus()
}, [done])
const set = (f: Field, v: string) => {
setValues((s) => ({ ...s, [f]: v }))
if (errors[f]) setErrors((s) => ({ ...s, [f]: check(f, v) }))
}
const blur = (f: Field, e: FocusEvent<HTMLInputElement>) => {
if (toButton(e)) return
if (values[f]) setErrors((s) => ({ ...s, [f]: check(f, values[f]) }))
}
const finish = (how: "email" | "google") => {
setBusy(how)
// Replace the timeout with your sign-in call (or the redirect to Google).
timer.current = setTimeout(() => {
setBusy("")
setDone(how)
}, 1200)
}
const onSubmit = (e: FormEvent) => {
e.preventDefault()
const next = { email: check("email", values.email), password: check("password", values.password) }
setErrors(next)
const first = (["email", "password"] as const).find((f) => next[f])
if (first) document.getElementById(`${id}-${first}`)?.focus()
else finish("email")
}
return (
<section aria-labelledby={`${id}-title`} className="grid min-h-[680px] bg-background lg:min-h-[760px] lg:grid-cols-2">
<div className="flex min-w-0 flex-col px-5 py-6 sm:px-10">
<a href="#home" className={`w-fit ${focus}`} aria-label="Orbit home">
<Logo />
</a>
<div className="mx-auto my-auto w-full max-w-[380px] py-14">
{done ? (
<div role="status">
<span className="grid size-12 place-items-center rounded-full bg-[color:var(--dc-highlight)] text-[color:var(--dc-highlight-fg)]">
<Check className="size-5" aria-hidden="true" />
</span>
<h1 id={`${id}-title`} ref={doneTitle} tabIndex={-1} className="dc-h mt-6 text-[32px] leading-[1.1] outline-none">
Good to see you again
</h1>
<p className="mt-3 text-[15px] leading-relaxed text-muted-foreground">
{done === "google" ? "You signed in with Google." : "You're signed in."} Northlight paid INV-1040 while you were away.
</p>
<Button className="mt-7 h-10 px-5 text-[15px] font-semibold" nativeButton={false} render={<a href="#overview" />}>
Open your overview <ArrowRight className="size-4" aria-hidden="true" />
</Button>
</div>
) : (
<>
<h1 id={`${id}-title`} className="dc-h text-[32px] leading-[1.1]">
Welcome back
</h1>
<p className="mt-2.5 text-[15px] leading-relaxed text-pretty text-muted-foreground">Sign in to see who has paid and who needs a nudge.</p>
<form noValidate onSubmit={onSubmit} className="mt-8 grid gap-4">
<FieldRow id={`${id}-email`} label="Email" error={errors.email}>
<Input
id={`${id}-email`}
type="email"
autoComplete="email"
placeholder="you@studio.com"
value={values.email}
onChange={(e) => set("email", e.target.value)}
onBlur={(e) => blur("email", e)}
aria-invalid={errors.email ? true : undefined}
aria-describedby={errors.email ? `${id}-email-error` : undefined}
className="h-10"
/>
</FieldRow>
<FieldRow
id={`${id}-password`}
label="Password"
error={errors.password}
aside={
<a href="#forgot-password" className={`text-[13px] font-medium text-[color:var(--dc-accent)] hover:underline ${focus}`}>
Forgot it?
</a>
}
>
<div className="relative">
<Input
id={`${id}-password`}
type={show ? "text" : "password"}
autoComplete="current-password"
value={values.password}
onChange={(e) => set("password", e.target.value)}
onBlur={(e) => blur("password", e)}
aria-invalid={errors.password ? true : undefined}
aria-describedby={errors.password ? `${id}-password-error` : undefined}
className="h-10 pr-11"
/>
<button
type="button"
onClick={() => setShow((s) => !s)}
aria-label="Show password"
aria-pressed={show}
className="absolute inset-y-0 right-1 my-auto grid size-8 place-items-center rounded-[calc(var(--radius)-2px)] text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50"
>
{show ? <EyeOff className="size-4" aria-hidden="true" /> : <Eye className="size-4" aria-hidden="true" />}
</button>
</div>
</FieldRow>
<Button type="submit" className="mt-2 h-10 w-full text-[15px] font-semibold" disabled={!!busy}>
{busy === "email" ? <LoaderCircle className="size-4 animate-spin motion-reduce:animate-none" aria-hidden="true" /> : null}
{busy === "email" ? "Signing in…" : "Sign in"}
</Button>
<Button type="button" variant="outline" className="h-10 w-full text-[14px] font-medium" disabled={!!busy} onClick={() => finish("google")}>
{busy === "google" ? <LoaderCircle className="size-4 animate-spin motion-reduce:animate-none" aria-hidden="true" /> : <GoogleMark />}
Sign in with Google
</Button>
<p className="sr-only" aria-live="polite">
{busy ? "Signing in…" : ""}
</p>
</form>
<p className="mt-8 text-[14px] text-muted-foreground">
No account yet?{" "}
<a href="#sign-up" className={`font-semibold text-foreground hover:underline ${focus}`}>
Start free
</a>
</p>
</>
)}
</div>
<footer className="flex flex-wrap gap-x-5 gap-y-1 text-[13px] text-muted-foreground">
<span>© 2026 Orbit Labs</span>
{["Privacy", "Terms", "Help"].map((l) => (
<a key={l} href={`#${l.toLowerCase()}`} className={`hover:text-foreground ${focus}`}>
{l}
</a>
))}
</footer>
</div>
<BandPanel />
</section>
)
}Magic link
Email only. After sending, it says where the link went, with a resend button that counts down and a way to change the address.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/login-magic-link.json"use client"
// Login, magic link: email only, no password. After the email is sent the page says where it went, with
// a resend button that counts down before it can be used again and a way to change the address (the
// form comes back with the address in it). Wire send() to your own magic-link endpoint.
import { ArrowLeft, LoaderCircle, Mail, MailCheck, RotateCw } from "lucide-react"
import { type FocusEvent, type FormEvent, useEffect, useId, useRef, useState } from "react"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
const WAIT = 30
const focus = "rounded-[2px] outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
// Leaving a field for a button in the same form (submit, the password toggle) skips the blur check: an
// error appearing above that button would move it out from under the click. Submit checks everything.
const toButton = (e: FocusEvent<HTMLInputElement>) => e.relatedTarget instanceof HTMLButtonElement && e.relatedTarget.form === e.currentTarget.form
const check = (v: string) => (!v.trim() ? "Enter your email." : EMAIL.test(v.trim()) ? "" : "That doesn't look like an email address.")
const clock = (s: number) => `0:${String(s).padStart(2, "0")}`
function Logo() {
return (
<span className="inline-flex items-center gap-2 text-[18px] font-bold tracking-[-0.02em]">
<svg width="22" height="22" viewBox="0 0 22 22" aria-hidden="true">
<circle cx="11" cy="11" r="8.5" fill="none" stroke="currentColor" strokeWidth="3" />
<circle cx="16.5" cy="5.5" r="3" fill="var(--dc-accent)" />
</svg>
<span className="dc-h">Orbit</span>
</span>
)
}
export default function LoginMagicLink() {
const id = useId()
const [email, setEmail] = useState("")
const [error, setError] = useState("")
const [busy, setBusy] = useState(false)
const [sent, setSent] = useState("")
const [left, setLeft] = useState(0)
const [resent, setResent] = useState(0)
const timer = useRef<ReturnType<typeof setTimeout>>(undefined)
const input = useRef<HTMLInputElement>(null)
const title = useRef<HTMLHeadingElement>(null)
const back = useRef(false)
useEffect(() => () => clearTimeout(timer.current), [])
// The resend countdown: one tick a second until it reaches zero.
useEffect(() => {
if (left <= 0) return
const t = setTimeout(() => setLeft((n) => n - 1), 1000)
return () => clearTimeout(t)
}, [left])
useEffect(() => {
if (sent) title.current?.focus()
else if (back.current) input.current?.focus()
}, [sent])
const send = (address: string, again = false) => {
setBusy(true)
// Replace the timeout with your call that emails the link.
timer.current = setTimeout(() => {
setBusy(false)
setSent(address)
setLeft(WAIT)
if (again) setResent((n) => n + 1)
}, 900)
}
const onSubmit = (e: FormEvent) => {
e.preventDefault()
const msg = check(email)
setError(msg)
if (msg) input.current?.focus()
else send(email.trim())
}
const change = () => {
back.current = true
setSent("")
setResent(0)
setLeft(0)
}
return (
<section aria-labelledby={`${id}-title`} className="flex min-h-[680px] flex-col bg-background">
<header className="flex h-16 items-center justify-between gap-4 px-5 sm:px-8">
<a href="#home" className={focus} aria-label="Orbit home">
<Logo />
</a>
<a href="#help" className={`text-[14px] font-medium text-muted-foreground hover:text-foreground ${focus}`}>
Need help?
</a>
</header>
<div className="flex flex-1 items-center justify-center px-5 py-14 sm:px-8">
<div className="w-full max-w-[400px] text-center">
{sent ? (
<>
<span className="mx-auto grid size-14 place-items-center rounded-full bg-[color:var(--dc-highlight)] text-[color:var(--dc-highlight-fg)]">
<MailCheck className="size-6" aria-hidden="true" />
</span>
<h1 id={`${id}-title`} ref={title} tabIndex={-1} className="dc-h mt-6 text-[32px] leading-[1.1] outline-none sm:text-[36px]">
Check your inbox
</h1>
<p className="mt-3 text-[16px] leading-relaxed text-muted-foreground">
We sent a sign-in link to <span className="font-semibold [overflow-wrap:anywhere] text-foreground">{sent}</span>. It works once, for the next 15 minutes.
</p>
<div className="dc-card mt-8 grid gap-3 p-4 text-left sm:p-5">
<p className="text-[14px] leading-relaxed text-muted-foreground">
Can’t find it? Look in spam, or search your mail for “Orbit sign-in”.
</p>
<div className="flex flex-wrap items-center gap-2">
<Button variant="outline" className="h-10 px-4" disabled={left > 0 || busy} onClick={() => send(sent, true)}>
{busy ? <LoaderCircle className="size-4 animate-spin motion-reduce:animate-none" aria-hidden="true" /> : <RotateCw className="size-4" aria-hidden="true" />}
{busy ? (
"Sending…"
) : left > 0 ? (
<span>
Resend in <span className="dc-num">{clock(left)}</span>
</span>
) : (
"Resend link"
)}
</Button>
<Button variant="ghost" className="h-10 px-3" onClick={change}>
<ArrowLeft className="size-4" aria-hidden="true" /> Use a different email
</Button>
</div>
</div>
<p className="mt-4 min-h-5 text-[13px] text-muted-foreground" aria-live="polite">
{resent ? "We sent a new link. Use the newest email; older links stop working." : ""}
</p>
</>
) : (
<>
<span className="dc-icon mx-auto size-14">
<Mail className="size-6" aria-hidden="true" />
</span>
<h1 id={`${id}-title`} className="dc-h mt-6 text-[32px] leading-[1.1] sm:text-[36px]">
Sign in with a link
</h1>
<p className="mt-3 text-[16px] leading-relaxed text-muted-foreground">Enter your email and we’ll send you a link that signs you in. Nothing to remember.</p>
<form noValidate onSubmit={onSubmit} className="mt-8 grid gap-3 text-left">
<div className="grid gap-1.5">
<Label htmlFor={`${id}-email`} className="text-[13px]">
Email
</Label>
<Input
ref={input}
id={`${id}-email`}
type="email"
autoComplete="email"
placeholder="you@studio.com"
value={email}
onChange={(e) => {
setEmail(e.target.value)
if (error) setError(check(e.target.value))
}}
onBlur={(e) => email && !toButton(e) && setError(check(email))}
aria-invalid={error ? true : undefined}
aria-describedby={error ? `${id}-error` : undefined}
className="h-11"
/>
{error ? (
<p id={`${id}-error`} className="text-[13px] text-destructive">
{error}
</p>
) : null}
</div>
<Button type="submit" className="h-11 w-full text-[15px] font-semibold" disabled={busy}>
{busy ? <LoaderCircle className="size-4 animate-spin motion-reduce:animate-none" aria-hidden="true" /> : null}
{busy ? "Sending your link…" : "Email me a sign-in link"}
</Button>
</form>
<p className="mt-6 text-[14px] text-muted-foreground">
Prefer a password?{" "}
<a href="#password" className={`font-semibold text-foreground hover:underline ${focus}`}>
Sign in with password
</a>
</p>
</>
)}
</div>
</div>
<footer className="flex flex-wrap justify-center gap-x-5 gap-y-1 px-5 pb-6 text-[13px] text-muted-foreground">
<span>© 2026 Orbit Labs</span>
{["Privacy", "Terms", "Status"].map((l) => (
<a key={l} href={`#${l.toLowerCase()}`} className={`hover:text-foreground ${focus}`}>
{l}
</a>
))}
</footer>
</section>
)
}Two-step code
A six-digit code that checks itself when the last digit is in, an error for a wrong one, resend and a backup code. In the demo, 123456 is right.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/login-two-factor.json"use client"
// Login, two-step code: six digits in the shadcn InputOTP. The code is checked as soon as the sixth digit
// is in (or on Verify); a wrong one shows an error on the slots and clears them. Resend counts down
// before it can be used again, and a backup code can stand in for the phone. In this demo 123456 is the
// right code and any backup code shaped like 4f7k-29xq works; replace verify() with your own check.
import { ArrowRight, Check, KeyRound, LoaderCircle, ShieldCheck, Smartphone } from "lucide-react"
import { type FocusEvent, type FormEvent, useEffect, useId, useRef, useState } from "react"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { Input } from "@/components/ui/input"
import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from "@/components/ui/input-otp"
import { Label } from "@/components/ui/label"
const WAIT = 30
const BACKUP = /^[a-z0-9]{4}-?[a-z0-9]{4}$/i
const focus = "rounded-[2px] outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
// Leaving a field for a button in the same form (submit, the password toggle) skips the blur check: an
// error appearing above that button would move it out from under the click. Submit checks everything.
const toButton = (e: FocusEvent<HTMLInputElement>) => e.relatedTarget instanceof HTMLButtonElement && e.relatedTarget.form === e.currentTarget.form
const clock = (s: number) => `0:${String(s).padStart(2, "0")}`
const slot = "size-10 text-[18px] dc-num font-semibold sm:size-12 sm:text-[20px] bg-[color:var(--card)]"
export default function LoginTwoFactor() {
const id = useId()
const [mode, setMode] = useState<"code" | "backup">("code")
const [code, setCode] = useState("")
const [backup, setBackup] = useState("")
const [error, setError] = useState("")
const [checking, setChecking] = useState(false)
const [done, setDone] = useState(false)
const [trust, setTrust] = useState(true)
const [left, setLeft] = useState(WAIT)
const [resent, setResent] = useState(false)
const timer = useRef<ReturnType<typeof setTimeout>>(undefined)
const otp = useRef<HTMLInputElement>(null)
const backupInput = useRef<HTMLInputElement>(null)
const doneTitle = useRef<HTMLHeadingElement>(null)
useEffect(() => () => clearTimeout(timer.current), [])
useEffect(() => {
if (left <= 0) return
const t = setTimeout(() => setLeft((n) => n - 1), 1000)
return () => clearTimeout(t)
}, [left])
useEffect(() => {
if (done) doneTitle.current?.focus()
}, [done])
const verify = (value: string) => {
setChecking(true)
setError("")
// Replace the timeout with your own check of the code.
timer.current = setTimeout(() => {
setChecking(false)
const ok = mode === "backup" ? BACKUP.test(value.trim()) : value === "123456"
if (ok) return setDone(true)
if (mode === "code") {
setError("That code didn't work. Check the newest text from Orbit and try again.")
setCode("")
requestAnimationFrame(() => otp.current?.focus())
} else {
setError("That backup code didn't work. Each one works only once.")
backupInput.current?.focus()
}
}, 900)
}
const onSubmit = (e: FormEvent) => {
e.preventDefault()
if (mode === "code") {
if (code.length < 6) {
setError("Enter all six digits.")
otp.current?.focus()
} else verify(code)
} else if (!BACKUP.test(backup.trim())) {
setError(backup.trim() ? "Backup codes look like 4f7k-29xq." : "Enter one of your backup codes.")
backupInput.current?.focus()
} else verify(backup)
}
const switchMode = (m: "code" | "backup") => {
setMode(m)
setError("")
requestAnimationFrame(() => (m === "code" ? otp.current : backupInput.current)?.focus())
}
const resend = () => {
// Send a new code here.
setLeft(WAIT)
setResent(true)
setError("")
setCode("")
}
return (
<section aria-labelledby={`${id}-title`} className="flex min-h-[700px] items-center justify-center bg-muted px-4 py-16 sm:px-8">
<div className="dc-card w-full max-w-[460px] overflow-hidden">
{done ? (
<div role="status" className="flex flex-col items-center px-6 py-14 text-center sm:px-10">
<span className="grid size-14 place-items-center rounded-full bg-[color:var(--dc-highlight)] text-[color:var(--dc-highlight-fg)]">
<Check className="size-6" aria-hidden="true" />
</span>
<h1 id={`${id}-title`} ref={doneTitle} tabIndex={-1} className="dc-h mt-6 text-[26px] leading-tight outline-none">
You’re in
</h1>
<p className="mt-2 max-w-[320px] text-[15px] leading-relaxed text-muted-foreground">
{trust ? "We won't ask for a code on this device for 30 days." : "We'll ask for a code the next time you sign in."}
{mode === "backup" ? " That backup code is used up now; you have 9 left." : ""}
</p>
<Button className="mt-7 h-10 px-5 text-[15px] font-semibold" nativeButton={false} render={<a href="#overview" />}>
Continue to Orbit <ArrowRight className="size-4" aria-hidden="true" />
</Button>
</div>
) : (
<>
<form noValidate onSubmit={onSubmit} className="flex flex-col items-center px-5 pt-9 pb-8 text-center sm:px-10">
<span className="dc-icon size-12">
{mode === "code" ? <ShieldCheck className="size-5" aria-hidden="true" /> : <KeyRound className="size-5" aria-hidden="true" />}
</span>
<h1 id={`${id}-title`} className="dc-h mt-5 text-[26px] leading-tight">
{mode === "code" ? "Enter your code" : "Use a backup code"}
</h1>
<p className="mt-2 max-w-[340px] text-[15px] leading-relaxed text-muted-foreground">
{mode === "code" ? (
<>
We texted a 6-digit code to your phone ending in <span className="dc-num font-medium text-foreground">42</span>. It expires in 10 minutes.
</>
) : (
"Enter one of the codes you saved when you turned on two-step sign-in. Each works once."
)}
</p>
<p className="mt-4 inline-flex items-center gap-2 rounded-full border border-border py-1 pr-3 pl-1 text-[13px]">
<span aria-hidden="true" className="grid size-6 place-items-center rounded-full bg-muted text-[10px] font-bold">
AR
</span>
ada@ruizstudio.co
<a href="#sign-in" className={`font-medium text-[color:var(--dc-accent)] hover:underline ${focus}`}>
Not you?
</a>
</p>
<div className="mt-7 grid w-full justify-items-center gap-2">
{mode === "code" ? (
<>
<Label htmlFor={`${id}-code`} className="sr-only">
Six-digit code
</Label>
<InputOTP
ref={otp}
id={`${id}-code`}
maxLength={6}
pattern="^\d+$"
inputMode="numeric"
autoComplete="one-time-code"
value={code}
onChange={(v) => {
setCode(v)
if (error) setError("")
}}
onComplete={verify}
disabled={checking}
aria-invalid={error ? true : undefined}
aria-describedby={error ? `${id}-error` : undefined}
containerClassName="gap-2 sm:gap-3"
>
<InputOTPGroup>
{[0, 1, 2].map((i) => (
<InputOTPSlot key={i} index={i} className={slot} aria-invalid={error ? true : undefined} />
))}
</InputOTPGroup>
<InputOTPSeparator className="text-muted-foreground" />
<InputOTPGroup>
{[3, 4, 5].map((i) => (
<InputOTPSlot key={i} index={i} className={slot} aria-invalid={error ? true : undefined} />
))}
</InputOTPGroup>
</InputOTP>
</>
) : (
<div className="grid w-full max-w-[300px] gap-1.5 text-left">
<Label htmlFor={`${id}-backup`} className="text-[13px]">
Backup code
</Label>
<Input
ref={backupInput}
id={`${id}-backup`}
autoComplete="off"
spellCheck={false}
placeholder="xxxx-xxxx"
value={backup}
onChange={(e) => {
setBackup(e.target.value)
if (error) setError("")
}}
onBlur={(e) => backup.trim() && !toButton(e) && !BACKUP.test(backup.trim()) && setError("Backup codes look like 4f7k-29xq.")}
aria-invalid={error ? true : undefined}
aria-describedby={error ? `${id}-error` : undefined}
className="dc-num h-11 text-center text-[17px] tracking-[0.12em]"
/>
</div>
)}
<p id={`${id}-error`} role="alert" className="min-h-5 max-w-[340px] text-[13px] text-destructive">
{error}
</p>
</div>
<label className="mt-2 flex items-center gap-2.5 text-[14px]">
<Checkbox checked={trust} onCheckedChange={(v) => setTrust(v === true)} />
Trust this device for 30 days
</label>
<Button type="submit" className="mt-6 h-10 w-full max-w-[340px] text-[15px] font-semibold" disabled={checking}>
{checking ? <LoaderCircle className="size-4 animate-spin motion-reduce:animate-none" aria-hidden="true" /> : null}
{checking ? "Checking…" : "Verify"}
</Button>
</form>
<p className="sr-only" aria-live="polite">
{resent && mode === "code" ? "We texted you a new code." : ""}
</p>
<div className="flex flex-col items-center gap-2 border-t border-border bg-muted/60 px-5 py-4 text-[14px] sm:flex-row sm:justify-between sm:px-8">
{mode === "code" ? (
<p className="text-muted-foreground">
{left > 0 ? (
<>
{resent ? "New code sent. " : "No text yet? "}Resend in <span className="dc-num">{clock(left)}</span>
</>
) : (
<>
No text yet?{" "}
<button type="button" onClick={resend} className={`font-medium text-foreground underline underline-offset-2 hover:text-[color:var(--dc-accent)] ${focus}`}>
Resend code
</button>
</>
)}
</p>
) : (
<button type="button" onClick={() => switchMode("code")} className={`inline-flex items-center gap-1.5 font-medium text-foreground hover:underline ${focus}`}>
<Smartphone className="size-4 text-muted-foreground" aria-hidden="true" />
Use the code from your phone
</button>
)}
{mode === "code" ? (
<button type="button" onClick={() => switchMode("backup")} className={`inline-flex items-center gap-1.5 font-medium text-foreground hover:underline ${focus}`}>
<KeyRound className="size-4 text-muted-foreground" aria-hidden="true" />
Use a backup code instead
</button>
) : (
<a href="#recovery" className={`font-medium text-muted-foreground hover:text-foreground ${focus}`}>
Lost your codes too?
</a>
)}
</div>
</>
)}
</div>
</section>
)
}
Providers first
Google, GitHub, Apple and single sign-on on one side, then email on the other; single sign-on turns the email side into a company lookup.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/login-social.json