> For the complete documentation index, see [llms.txt](https://docs.adminjs.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.adminjs.co/installation/plugins/hapi.md).

# Hapi

{% hint style="info" %}
Make sure you have installed AdminJS packages described in [Getting started](/installation/getting-started.md) article.

```bash
$ yarn add adminjs @adminjs/hapi
```

{% endhint %}

To setup AdminJS panel with Hapi you need to have `@hapi/hapi` installed and required peer dependencies:

```bash
$ yarn add @hapi/hapi @hapi/boom @hapi/cookie @hapi/inert
```

Afterwards, follow one of the examples below.

### Simple

{% tabs %}
{% tab title="Javascript" %}
{% code title="app.js" %}

```javascript
import AdminJSHapi from '@adminjs/hapi'
import Hapi from '@hapi/hapi'

const PORT = 3000

const start = async () => {
  const server = Hapi.server({ port: PORT })

  const adminOptions: ExtendedAdminJSOptions = {
    resources: [],
    rootPath: '/admin',
    auth: {
      isSecure: process.env.NODE_ENV === 'production',
    },
    registerInert: true,
  }

  await server.register({
    plugin: AdminJSHapi,
    options: adminOptions,
  })

  await server.start();
  console.log(`AdminJS available at ${server.info.uri}${adminOptions.rootPath}`);
}

start()
```

{% endcode %}
{% endtab %}

{% tab title="Typescript" %}
{% code title="app.ts" %}

```typescript
import AdminJSHapi, { ExtendedAdminJSOptions } from '@adminjs/hapi'
import Hapi from '@hapi/hapi'

const PORT = 3000

const start = async () => {
  const server = Hapi.server({ port: PORT })

  const adminOptions: ExtendedAdminJSOptions = {
    resources: [],
    rootPath: '/admin',
    auth: {
      isSecure: process.env.NODE_ENV === 'production',
    },
    registerInert: true,
  }

  await server.register<ExtendedAdminJSOptions>({
    plugin: AdminJSHapi,
    options: adminOptions,
  })

  await server.start();
  console.log(`AdminJS available at ${server.info.uri}${adminOptions.rootPath}`);
}

start()
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Authentication

To add authentication, all you have to do is extend `auth` config with `authenticate`, `cookieName` and `cookiePassword`.

{% tabs %}
{% tab title="Javascript" %}
{% code title="app.js" %}

```javascript
import AdminJSHapi from '@adminjs/hapi'
import Hapi from '@hapi/hapi'

const PORT = 3000

const DEFAULT_ADMIN = {
  email: 'admin@example.com',
  password: 'password',
}

const authenticate = async (email, password) => {
  if (email === DEFAULT_ADMIN.email && password === DEFAULT_ADMIN.password) {
    return Promise.resolve(DEFAULT_ADMIN)
  }
  return null
}

const start = async () => {
  const server = Hapi.server({ port: PORT })

  // "secret" must be a string with at least 32 characters, example:
  const cookieSecret = 'sieL67H7GbkzJ4XCoH0IHcmO1hGBSiG5'
  const adminOptions = {
    resources: [],
    rootPath: '/admin',
    auth: {
      isSecure: process.env.NODE_ENV === 'production',
      authenticate,
      cookieName: 'adminjs',
      cookiePassword: cookieSecret,
    },
    registerInert: true,
  }

  await server.register({
    plugin: AdminJSHapi,
    options: adminOptions,
  })

  await server.start();
  console.log(`AdminJS available at ${server.info.uri}${adminOptions.rootPath}`);
}

start()
```

{% endcode %}
{% endtab %}

{% tab title="Typescript" %}
{% code title="app.ts" %}

```typescript
import AdminJSHapi, { ExtendedAdminJSOptions } from '@adminjs/hapi'
import Hapi from '@hapi/hapi'

const PORT = 3000

const DEFAULT_ADMIN = {
  email: 'admin@example.com',
  password: 'password',
}

const authenticate = async (email: string, password: string): Promise<Record<string, unknown> | null> => {
  if (email === DEFAULT_ADMIN.email && password === DEFAULT_ADMIN.password) {
    return Promise.resolve(DEFAULT_ADMIN)
  }
  return null
}

const start = async () => {
  const server = Hapi.server({ port: PORT })

  // "secret" must be a string with at least 32 characters, example:
  const cookieSecret = 'sieL67H7GbkzJ4XCoH0IHcmO1hGBSiG5'
  const adminOptions: ExtendedAdminJSOptions = {
    resources: [],
    rootPath: '/admin',
    auth: {
      isSecure: process.env.NODE_ENV === 'production',
      authenticate,
      cookieName: 'adminjs',
      cookiePassword: cookieSecret,
    },
    registerInert: true,
  }

  await server.register<ExtendedAdminJSOptions>({
    plugin: AdminJSHapi,
    options: adminOptions,
  })

  await server.start();
  console.log(`AdminJS available at ${server.info.uri}${adminOptions.rootPath}`);
}

start()
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.adminjs.co/installation/plugins/hapi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
