A sign-up form collects a name, an email address and a password, and Better Auth turns them into an account. This guide builds a Better Auth sign-up form in Next.js with authClient.signUp.email, creates an account with it, and shows what happens when the email address is already taken.
The short answer: in a client component, call authClient.signUp.email({ name, email, password }). Better Auth creates the user, stores a hash of the password and, by default, signs the new user in.
Syntax
const { data, error } = await authClient.signUp.email({
name: "<display name>",
email: "<email address>",
password: "<password>",
image: "<picture address>",
callbackURL: "<page address>",
});
name: the name the person goes by. Required.email: the email address they’ll sign in with. Required.password: their password, 8 to 128 characters by default. Required.image: the address of a profile picture. Optional.callbackURL: the page to open after the person verifies their email address. Optional.dataholds the result when it works, anderrorholds the reason when it doesn’t, with a readableerror.message.
The reference: Sign Up (opens in a new tab) in the Better Auth documentation.
Prerequisites
- Better Auth set up in a Next.js app, with email and password sign-in switched on:
emailAndPassword: { enabled: true }in your auth settings (Enable Email and Password (opens in a new tab)).
Step 1: Create the Sign-Up Page
The example is a small bookshop app with a header that shows who’s signed in. In the app folder, create a folder named sign-up, and in it a file named page.tsx:
"use client";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { type FormEvent, useState } from "react";
import { authClient } from "@/lib/auth-client";
export default function SignUpPage() {
const router = useRouter();
const [errorMessage, setErrorMessage] = useState("");
const [isPending, setIsPending] = useState(false);
async function handleSubmit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
const form = new FormData(event.currentTarget);
setErrorMessage("");
setIsPending(true);
const { error } = await authClient.signUp.email({
name: String(form.get("name")),
email: String(form.get("email")),
password: String(form.get("password")),
});
setIsPending(false);
if (error) {
setErrorMessage(error.message ?? "Sign-up failed. Please try again.");
return;
}
router.push("/");
}
return (
<main className="mx-auto w-full max-w-sm flex-1 px-6 py-12">
<h1 className="text-2xl font-semibold">Create your account</h1>
<form onSubmit={handleSubmit} className="mt-6 flex flex-col gap-4">
<label className="flex flex-col gap-1 text-sm">
Name
<input
name="name"
required
autoComplete="name"
className="rounded border border-zinc-300 px-3 py-2 dark:border-zinc-700"
/>
</label>
<label className="flex flex-col gap-1 text-sm">
Email
<input
name="email"
type="email"
required
autoComplete="email"
className="rounded border border-zinc-300 px-3 py-2 dark:border-zinc-700"
/>
</label>
<label className="flex flex-col gap-1 text-sm">
Password
<input
name="password"
type="password"
required
minLength={8}
autoComplete="new-password"
className="rounded border border-zinc-300 px-3 py-2 dark:border-zinc-700"
/>
</label>
{errorMessage && (
<p role="alert" className="text-sm text-red-600">
{errorMessage}
</p>
)}
<button
type="submit"
disabled={isPending}
className="rounded bg-zinc-900 px-4 py-2 text-white disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-900"
>
{isPending ? "Creating account…" : "Sign up"}
</button>
</form>
<p className="mt-6 text-sm">
Already have an account?{" "}
<Link href="/sign-in" className="underline">
Sign in
</Link>
</p>
</main>
);
}
"use client": the form runs in the browser, where Better Auth’s client works.authClient.signUp.email(…)sends the three fields to Better Auth.- When
erroris set, the page showserror.message. Otherwiserouter.push("/")opens the home page. minLength={8}matches Better Auth’s default minimum, so the browser catches a short password first.
Step 2: Create an Account
Open /sign-up in your browser and fill in the form. Here it’s Lena Park, a customer of the bookshop:

Click Sign up. Better Auth creates the account and signs Lena in, so the header shows her name:

Step 3: Try an Email Address That’s Taken
Sign out, open /sign-up again and sign up with the same email address:

Better Auth refuses with status 422 and the message User already exists. Use another email., which the form shows.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Calling signUp.email on the server | It’s the browser client, meant for client components | Keep it in a component that starts with "use client" |
Ignoring error | A failed sign-up looks like nothing happened | Show error.message next to the form |
FAQ
Why is the new user signed in straight away?
autoSignIn is true by default. Set autoSignIn: false in emailAndPassword to make new users sign in themselves.
Can I collect more than a name?
Yes, with additional fields on the user (Extending core schema (opens in a new tab)). Part 6 of the Better Auth Tutorial covers it.
Conclusion
authClient.signUp.email turns a name, an email address and a password into an account, and signs the person in. Show error.message when it fails, such as for an email address that already has an account.
Additional Resources
- Email & Password (opens in a new tab) in the Better Auth documentation
- Basic usage: Sign Up (opens in a new tab)
- Handling errors (opens in a new tab) in the client
Related
- Better Auth Tutorial — Part 3: Sign Up and Sign In with Email and Password, where this is one step of the full setup
Better Auth, Next.js and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by Better Auth, Inc. or Vercel.
0 comments