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

# Verification

## Overview

Email verification helps confirm user identities by requiring them to verify their email addresses before gaining full access. This is especially useful for preventing spam and unauthorized access.

When a user signs up, Nile Auth:

1. Sends a verification email using your configured SMTP server.
2. Generates a unique `verification_token` for the user.
3. Grants access to the user after they click the verification link.

## Prerequisites

* A configured SMTP server is required to send verification emails. You can set this up in the Nile Auth UI under **Tenants & Users -> Configuration -> Email templates**.
* A web server configured to handle Nile Auth requests and serve html.

## Implementation

**1. Install dependencies**

```bash theme={null}
npm install @niledatabase/server @niledatabase/react
@niledatabase/client @niledatabase/nextjs
```

**Step 2**

Your application must expose API routes to handle authentication operations.

Create a folder called `api` under the `app` folder and a folder called `[...nile]` under it:

```bash theme={null}
mkdir -p app/api/\[...nile\]
```

Create following files handle the calls to your server, as well as expose the `nile` instance to your application:

```typescript app/api/[...nile]/nile.ts theme={null}
import { Nile } from '@niledatabase/server';
import { nextJs } from '@niledatabase/nextjs';

export const nile = Nile({ extensions: [nextJs] });
```

```typescript app/api/[...nile]/route.ts theme={null}
import { nile } from './nile';
export const { POST, GET, DELETE, PUT } = nile.handlers;
```

**3. Middleware for Verification Enforcement**

```typescript theme={null}
import { Nile } from "@niledatabase/server";

export const nile = Nile();

app.use("verification-page", async (req, res, next) => {
  const me = await nile.users.getSelf(req.headers);

  if (!me.emailVerified) {
    return res.redirect("/force-verification");
  }

  next();
});
```

This middleware ensures that unverified users are redirected to a verification page.

**4. Verification Button in the Frontend**

```typescript theme={null}
"use client";
import { User } from "@niledatabase/server";
import { EmailSignInButton } from "@niledatabase/react";

export default function VerifyButton({ me }: { me: User }) {
  return <EmailSignInButton email={me.email} />;
}
```

This button allows users to trigger email verification manually.

[https://storybook.thenile.dev/iframe.html?args=\&globals=\&id=social-email--verify-email-address](https://storybook.thenile.dev/iframe.html?args=\&globals=\&id=social-email--verify-email-address)

**5. Sign-in via Email**

You can also allow users to sign in directly using their email without requiring a password.

```typescript theme={null}
"use client";
import { EmailSignIn } from "@niledatabase/react";

export default function EmailLogin() {
  return <EmailSignIn />;
}
```

[https://storybook.thenile.dev/iframe.html?args=\&globals=\&id=social-email--sign-in-with-email](https://storybook.thenile.dev/iframe.html?args=\&globals=\&id=social-email--sign-in-with-email)

## **Verification flow**

1. The user inputs their email on the login/signup page.
2. Nile sends an email with a verification token using the configured SMTP settings.
3. The link exchanges the `verification_token` for an authenticated session.
4. Upon successful verification, the user can access the application.

## **Related Topics**

* [Email Templates](https://thenile.dev/docs/auth/email/templates.md) - Customize email verification messages.
* [Custom SMTP](https://thenile.dev/docs/auth/email/customsmtp.md) - Configure your own SMTP server for sending emails.
* [User Management](https://thenile.dev/docs/auth/concepts/users.md) - Manage user accounts in Nile Auth.


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