> For AI agents: the complete documentation index is available at https://dotpress.dev/llms.txt, the full documentation bundle is available at https://dotpress.dev/llms-full.txt.

# Sign-up

`signUp` adds `POST /auth/sign-up`: an account with an email address and a password. It needs [messages and links](https://dotpress.dev/auth/messages.md), and the `users` and `tokens` [stores](https://dotpress.dev/auth/data-provider.md#the-stores).

```ts
createAuth({
  // …
  messages: { send },
  links: { baseUrl: 'https://app.example.com' },
  signUp: {
    mode: 'open', // 'open' | 'invite_only' | 'closed'
    schema: (z) => ({ firstName: z.string().max(100) }),
  },
  emailVerification: { required: true },
})
```

```http
POST /auth/sign-up
{ "email": "grace@example.com", "password": "…", "firstName": "Grace", "redirectTo": "https://app.example.com/welcome", "codeChallenge": "…" }

202 { "status": "verification_sent" }
```

1. The password is checked against the [password policy](https://dotpress.dev/auth/passwords.md#password-policy): `400 WEAK_PASSWORD` with `data.rule`.
2. `users.create({ email, passwordHash, emailVerified: false, method: 'password', extra }, meta)` creates the account, inside the transaction of the step. `extra` holds the fields of `signUp.schema`, validated with the body.
3. With `emailVerification`, a verification link is sent (`email_verification`). `codeChallenge` (PKCE, S256) binds it to the browser that signs up: opened without its `codeVerifier` nor the password of the account, the link verifies the address but removes the password, which may be someone else's (see [Binding the link to the browser](https://dotpress.dev/auth/email-verification.md#binding-the-link-to-the-browser)).
4. The `user.signed_up` event is recorded.

The address is trimmed and lowercased before it reaches the data provider.

## Existing addresses

Without `autoLogin`, the address of an existing account gets the same answer, `202`, in a comparable time: nothing is written, and its owner receives a `sign_up_existing_account` message instead, with a password reset link when `passwordReset` is on. The answer does not tell which addresses have an account.

An address of a domain that logs in with its IdP ([SSO enforcement](https://dotpress.dev/auth/sso.md#discovery-and-enforcement)) answers `403 SSO_REQUIRED`, with `data.connectionId`.

## Starting a session

`signUp.autoLogin` starts a session at sign-up: the answer is the one of a login, `200 { status: 'authenticated', userId, accessToken, … }`, with `mode: 'cookie'` too. It defaults to `true` without `emailVerification`, and to `false` with it; `createAuth()` refuses it with `emailVerification.required`.

:::warning autoLogin reveals the accounts
With `autoLogin`, a new address gets `200` and a session, an existing one `202`: the answer tells whether an address has an account. Leave it off when the list of your users must stay private.
:::

With `emailVerification`, the session starts once the email is verified: see `emailVerification.autoLogin` in [Email verification](https://dotpress.dev/auth/email-verification.md). The verification revokes the sessions opened before it. What a session of an unverified account adds (passkeys, linked accounts, second factors) does not outlive the claim of the account by the owner of its address: it is removed with the password (see [Magic link](https://dotpress.dev/auth/magic-link.md#unverified-accounts)).

## Invitations and consents

`users.create()` runs in the transaction of the step: consume an invitation, record the accepted terms, create a workspace there. Throw `signUpRejected(reason)` to reject the sign-up: the route answers `400 SIGN_UP_REJECTED` with `data.reason`, and the transaction is rolled back.

```ts
import { signUpRejected } from '@dotpress/auth'

users: {
  async create({ email, passwordHash, extra }, meta) {
    const invitation = await db.invitations.consume(extra.invitationCode)
    if (!invitation) throw signUpRejected('INVITATION_INVALID')
    return { userId: await db.users.insert({ email, passwordHash, workspaceId: invitation.workspaceId }) }
  },
}
```

`users.create()` throws when another account uses the address, whatever its case: put a unique, case-insensitive constraint on the column.

`mode: 'invite_only'` documents that the sign-up needs an invitation, a field of `schema`; checking it is the job of `users.create()`. `mode: 'closed'` answers `403 SIGN_UP_DISABLED`, and closes the sign-up by [magic link](https://dotpress.dev/auth/magic-link.md#sign-up-by-link) and by [social login](https://dotpress.dev/auth/oauth.md) too.

## Cookie mode

With `mode: 'cookie'`, a request from an untrusted origin answers `403 CROSS_ORIGIN_REQUEST`: another site cannot open a session of its own in the browser of the user. See [CSRF](https://dotpress.dev/auth/cookies.md#protection-against-cross-site-request-forgery).

## Rate limits

5 sign-ups per hour per IP address (`rateLimits.signUp.ip`), and 3 per hour per address (`rateLimits.signUp.email`), then `429 TOO_MANY_REQUESTS` with `Retry-After`.

## Service

`auth.signUp.register({ email, password, extra?, redirectTo?, codeChallenge?, meta?, locale? })` does the same outside the routes: an import script, an admin console. It returns `{ status: 'verification_sent' | 'accepted' }`, or `{ status: 'authenticated', userId, tokens }`.
