If you have not done so yet, be sure you have obtained credentials from the
console.
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
ThenilePlugin 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.Auth.user and methods directly.
The Plugin
Under the hood, the elysia plugin does the following:- Registers Routes: Maps Nile’s internal route handlers to Elysia’s router (e.g.
app.get,app.post), exposing the full API. - Decorates Context: Adds the
nileserver instance to the Elysia context (ctx.nile), making it available in all downstream handlers and plugins. - Context Isolation: For the routes it registers, it wraps execution in
nile.withContextto ensure tenant isolation and proper authentication handling.