> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bludia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Email verification

> Turn on email verification for a guard to send new users a 6-character code by email at sign-up. Confirm it with POST /auth/{guard}/email/verify and resend with POST /auth/{guard}/email/resend.

With email verification on, Bludia emails new users a short code when they register. Their account status is `pending` until they confirm it, then it becomes `active`.

## Set it up

**1. Create an email channel**

Add an SMTP email channel in **Messaging** → **Channels**. See [Channels](https://docs.bludia.com/messaging/channels.md).

**2. Create a verification template**

Create an email template that includes the `{{token}}` variable:

```html theme={null}
Subject: Your verification code

<p>Welcome! Your verification code is <strong>{{token}}</strong>.</p>
```

**3. Enable it on the guard**

In the guard settings, turn on **Email verification** and select the channel and template.

## The flow

```text theme={null}
POST /auth/users/register   → 201 { session, status: "pending_verification" }
                              email sent to the login field value: "Your code is 7KQ2XF"
POST /auth/users/email/verify { token: "7KQ2XF" }
                            → 200 { message: "Email verified. You can now log in." }
                              record status: pending → active
```

## Verify

`POST /auth/{guard}/email/verify` — API key only.

```bash theme={null}
curl -X POST "$BASE_URL/auth/users/email/verify" \
  -H "Content-Type: application/json" \
  -H "X-BLUDIA-API-KEY: $BLUDIA_PUBLIC_KEY" \
  -d '{ "token": "7KQ2XF" }'
```

```json theme={null}
{ "message": "Email verified. You can now log in.", "status": 200 }
```

An unknown or already used code returns `401 invalid_or_expired_token`.

## Resend

`POST /auth/{guard}/email/resend` — needs the user's Bearer token. Issues a new code.

> [!WARNING]
>
> Beta: resent codes are not emailed automatically yet. The code sent at registration is delivered by email.

```bash theme={null}
curl -X POST "$BASE_URL/auth/users/email/resend" \
  -H "X-BLUDIA-API-KEY: $BLUDIA_PUBLIC_KEY" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

## Check verification status

[`GET /auth/{guard}/me`](https://docs.bludia.com/authentication/current-user) includes `verified_at` in the user's data once verified, and the record `status` is `active`.

> [!NOTE]
>
> Registration returns a session, and `pending` users can log in. If your app needs verified users only, check `verified_at` from `/me` and show a "verify your email" screen, or add a [row policy](https://docs.bludia.com/authorization/row-level-security.md) or [hook](https://docs.bludia.com/hooks/overview.md) that blocks unverified users from key actions.

> [!TIP]
>
> The code is sent to the value of the guard's login field, so use an email login field when you enable verification.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.