Remix
Integrate Nile Auth with Remix applications
Remix API Integration with Nile Database
This guide explains how to integrate Nile Database with Remix and set up routes for handling various HTTP requests (GET
, POST
, PUT
, DELETE
). Additionally, you’ll see how to include client-side components for user authentication and interaction using Nile’s React SDK.
Create a new Remix project
Run the following command in your terminal to create a new Remix project:
Follow the prompts and select the following options:
- TypeScript for the language.
- Express for the server.
- Install dependencies with npm for ease of use.
After creating the project, navigate into the newly created project directory:
Upgrade react and react-dom to be on v19 and @niledatabase/server
and @niledatabase/react
, as they have it as a dependency.
Obtain Database Credentials
- If you haven’t signed up for Nile yet, sign up here and follow the steps to create a database.
- Navigate to Database Settings in your database’s UI at console.thenile.dev.
- Go to Connection settings.
- Select the CLI icon, and click Generate credentials
- Copy the required credentials and store them in an
.env
file so they can be used in the application to connect to the Nile auth service.
Update the Server to Handle API Routes
Create the API route file at app/routes/api.$.ts
. This file will handle different HTTP methods (GET, POST, PUT, DELETE) using the Nile SDK.
This code handles different HTTP methods (GET
, POST
, PUT
, DELETE
) for the /api/*
route and delegates the logic to Nile Database.
Add Client-Side Code for Authentication
You can use the components from @niledatabase/react
to handle authentication. Replace the boilerplate of the main _index.tsx
file with the following:
app/routes/_index.tsx
This component will render:
- User info if the user is signed in.
- Sign-up form if the user is not signed in.
Running the Project
To run your project, execute the following:
This will start the development server at http://localhost:3000
, and you can test your API endpoints and authentication components.
Summary
Now you can interact with your Nile Database through Remix API routes and manage authentication in your app!
Creating a loader
In some cases, you may want to create specific action and loader around the API, to do that, use the server side functions in the sdk in your loader. This code loads and updates a user’s profile.
Related Topics
Was this page helpful?