This guide will help you get started with Nile Auth and Nitro. This guide outlines the steps required to configure and integrate authentication in your application. This guide uses the Nuxt layouts, and can be adjusted for any Nitro application
If you have not done so yet, be sure you have obtained credentials from the console.
1

Install packages

  npm install @niledatabase/server @niledatabase/nitro
2

Configure the extension

Create the base nile instance, extended with the nitro plugin
app/composables/useNile.ts
import { Nile } from "@niledatabase/server";
import { nitro } from "@niledatabase/nitro";
import type { withNitro } from "@niledatabase/nitro";

export const nile = Nile<withNitro>({
  debug: true,
  extensions: [nitro],
}));

3

Add the route so that the APIs can be handled
server/api/[...slug].ts
import { nile } from "~/composables/useNile";
export default defineEventHandler(nile.handlers);

The extension

Under the hood, the nitro extension does the following reconfigures handlers to use the h3 callbacks, vs the default. The default method calls are still handled the same way internally, it only modifies the base call. For instance, the calls on the server-side will still need to have their context set.
import { nile } from "~/composables/useNile";

const serverFunction = (event) => {
  const ctxNile = nile.withContext({ headers: event.headers });
  const userTenants = await ctxNile.tenants.list();
}