> ## 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.

# Self Host Nile Auth

> Learn how to self-host Nile Auth in your own infrastructure

**1. Prerequisites**

Nile provides a cloud offering to help build multi-tenant apps. You can also get started with Nile's Docker image
and try Nile locally. [Join our discord](https://discord.com/invite/8UuBB84tTy) to give feedback or ask questions about running Nile locally.

* [Docker](https://www.docker.com/get-started)
* Postgres client. We'll use `psql` in this guide.

**2. Run the Docker Container**

```bash theme={null}
docker run -p 5432:5432 -p 3000:3000 -ti ghcr.io/niledatabase/testingcontainer:latest
```

This will start a Postgres database with Nile extensions installed. It will also start Nile Auth (optional).
If this is the first time you are running the container, it will also pull the latest image,create the `test` database
and the `00000000-0000-0000-0000-000000000000` user.

Wait for the following message before connecting:

```text theme={null}
Database has been created and is ready
```

Leave the container running and open another terminal for the commands below.

**3. Connecting to the Database**

You can use `psql` with the following connection string:

```bash theme={null}
psql postgres://00000000-0000-0000-0000-000000000000:password@localhost:5432/test
```

Or, if you are using a different client, you use the following connection details:

```
Host: localhost
Port: 5432
Database: test
Username: 00000000-0000-0000-0000-000000000000
Password: password
```

**4. Test Nile Auth**

Nile Auth service is running and listening on port 3000. We will do a curl to check if you can reach it and if it is returning the right information.
The curl command queries the list of providers. By default, it should only have the email/credential option.

```bash theme={null}
curl http://localhost:3000/v2/databases/01000000-0000-7000-8000-000000000000/auth/providers
```

Output:

```bash theme={null}
{"credentials":{"id":"credentials","name":"credentials","type":"credentials","signinUrl":"https://null/api/auth/signin/credentials","callbackUrl":"https://null/api/auth/callback/credentials"}}%
```

**5. Run create-next-app**

This guide uses Next.js with App Router, Typescript and Tailwind CSS. If you have a different framework in mind, you can find additional guides under "Frameworks"
in the sidebar. Initialize a new Next.js project with the following command and give it a name:

```bash theme={null}
npx create-next-app@latest nile-app --yes
```

**6. Setup environment**

Create a .env file in the next app folder that you just created and paste the values below. This will make the Next app that we just created use the local Nile Postgres and Nile Auth.

```bash theme={null}
NILEDB_USER=00000000-0000-0000-0000-000000000000
NILEDB_PASSWORD=password
NILEDB_API_URL=http://localhost:3000/v2/databases/01000000-0000-7000-8000-000000000000
NILEDB_POSTGRES_URL=postgres://localhost:5432/test
```

**7. Install dependencies**

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

**Step 8**

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;
```

**9. Use SDK Components**

Your application will interact with above authentication routes using SDK components. Replace the boilerplate `app/page.tsx` with the following:

`/app/page.jsx`

```jsx theme={null}
import {
SignOutButton,
SignUpForm,
SignedIn,
SignedOut,
TenantSelector,
UserInfo,
} from "@niledatabase/react";
import "@niledatabase/react/styles.css";

export default function SignUpPage() {
return (
    <div className="flex flex-col items-center justify-center min-h-screen">
    <SignedIn className="flex flex-col gap-4">
        <UserInfo />
        <TenantSelector className="py-6 mb-10" />
        <SignOutButton />
    </SignedIn>
    <SignedOut>
        <SignUpForm createTenant />
    </SignedOut>
    </div>
);
}

```

**10. Run and Log in to your application**

```bash theme={null}
npm run dev
```

Navigate to localhost to see the page. You should see a signup form that looks like this:

![Signup Form](https://mintcdn.com/nile/6B-b9nH3DSiJ_Uwi/images/auth/quickstart_signup.png?fit=max\&auto=format\&n=6B-b9nH3DSiJ_Uwi\&q=85\&s=b43e34ede7a9d3ef7c398c16ea415ebe)

Enter a dummy email and password into the SignUpForm.

If all went well, you will be logged in automatically and see the user profile and an organization switcher that allows you to create new organizations and switch between them:

![User profile and organization switcher](https://mintcdn.com/nile/6B-b9nH3DSiJ_Uwi/images/auth/quickstart_authenticated.png?fit=max\&auto=format\&n=6B-b9nH3DSiJ_Uwi\&q=85\&s=617c6ff28ed9c42e88d7ef2ef5e646a3)

**11. Next Steps**

* [Explore Frontend Frameworks](https://thenile.dev/docs/auth/quickstarts/nextjs.md)
* [Learn About Backend Integration](https://thenile.dev/docs/auth/quickstarts/express.md)


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