Skip to main content
This guide will help you get started with Nile Auth and ElysiaJS. This guide outlines the steps required to configure and integrate authentication in your application.
If you have not done so yet, be sure you have obtained credentials from the console.
1

Install packages

2

Configure the extension

The simplest way to use Nile with Elysia is to register the plugin. This will automatically mount Nile’s default API routes (authentication, tenant management, etc.) onto your Elysia application.
app.ts

Accessing the Nile Instance

The nilePlugin automatically decorates the Elysia context with your nile server instance. This allows you to access it directly in your handlers for database queries or custom auth logic.

Deriving the User

For a more idiomatic Elysia experience, you can create a derivation that extracts the authenticated user from the context.

Custom Auth Helpers

You can extend the derivation pattern to expose helper methods that automatically handle context, making your handlers cleaner.
Now you can use the plugin in your application and access Auth.user and methods directly.

The Plugin

Under the hood, the elysia plugin does the following:
  1. Registers Routes: Maps Nile’s internal route handlers to Elysia’s router (e.g. app.get, app.post), exposing the full API.
  2. Decorates Context: Adds the nile server instance to the Elysia context (ctx.nile), making it available in all downstream handlers and plugins.
  3. Context Isolation: For the routes it registers, it wraps execution in nile.withContext to ensure tenant isolation and proper authentication handling.

Handlers and paths

The plugin iterates over the configured paths in the Nile Server SDK and registers them directly with your Elysia app instance. This ensures that all standard authentication and tenant management routes are available without manual configuration.