Server registration
A server-side registration handler needs to create an account without using the client SDK.
Better Auth · Module
Creates a user with email and password through Better Auth's server API. Supply required identity and credential fields, with optional image and callback URL values.
Call the server API with a body containing the new user's name, email, and password. Optional image and callbackURL values can add a profile image and post-signup destination; the response contains the created user and session data.
await auth.api.signUpEmail({ body: { name, email, password, image?, callbackURL? } });| Name | Type | Description |
|---|---|---|
body | object | Request payload containing the new user's required name, email, and password, plus optional image and callbackURL values. |
body.name | string | The user's display name. |
body.email | string | The user's email address. |
body.password | string | The user's password. |
body.image | string | Optional profile image URL. |
body.callbackURL | string | Optional post-signup redirect URL. |
The created user and session data; the server response may also set cookies that need to be returned to the client.
auth.api.signUpEmail and place request data under body.import { auth } from "@/lib/auth";
const result = await auth.api.signUpEmail({
body: {
name: "John Doe",
email: "john.doe@example.com",
password: "password1234",
image: "https://example.com/image.png",
callbackURL: "https://example.com/callback",
},
});
console.log(result.user);Creates a user through the server API using the required identity and password fields, with optional profile and callback values.
A server-side registration handler needs to create an account without using the client SDK.
Registration should attach a profile image during account creation.
The application needs to direct a newly registered user to a specific destination.
auth.api.signUpEmail?Pass the signup fields inside the body property of auth.api.signUpEmail. The documented required values are name, email, and password; image and callbackURL are optional.
Follow-up: What must happen when this endpoint creates a session? Its response cookies must be forwarded to the client so the session is retained.
The endpoint accepts an optional image URL for the user's profile image and an optional callbackURL for the destination after signup. Both belong in the request body alongside the required signup fields.
Follow-up: How would you support an additional signup field? Use the configured Better Auth schema or plugin field and include it in the body if that documentation exposes it.
The documented default password rule requires at least 8 characters and permits at most 128 characters. Inputs outside that range should be rejected by validation.
Follow-up: Would that rule necessarily be universal? No; treat it as the documented default and verify any configuration that changes password validation.
authClient.signUp.emailauth.api.signInEmailauth.api.verifyEmail