Self Host Nile Auth
Learn how to self-host Nile Auth in your own infrastructure
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 to give feedback or ask questions about running Nile locally.
- Docker
- Postgres client. We’ll use
psql
in this guide.
Run the Docker Container
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.
Connecting to the Database
You can use psql
with the following connection string:
Or, if you are using a different client, you use the following connection details:
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.
Output:
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:
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.
Install dependencies
Your application must expose API routes to handle authentication operations.
First, create a folder called api
under the app
folder and a folder called [...nile]
under it:
Create following files handle the calls to your server, as well as expose the nile
instance to your application:
/api/[...nile]/nile.ts
/api/[...nile]/route.ts
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
Run and Log in to your application
Navigate to localhost to see the page. You should see a signup form that looks like this:
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:
Was this page helpful?