Methods
# static register(server, options) → {Promise.<AdminBro>}
Actual method that Hapi uses under the hood when you call server.register(plugin, options) method. Options you give in Hapi are passed back to it.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
server |
Object | Hapi.js server |
||
options |
Object | options passed to AdminBro |
||
auth |
Object | Authentication options. You can pass here options described below and any other option supported by the https://github.com/hapijs/cookie |
||
auth.authenticate |
Object |
<optional> |
function takes email and password as arguments. Should return a logged in user or null (no authorization), if given options.auth.strategy is set to 'session' |
|
auth.strategy |
Object |
<optional> |
auth strategy for hapi.js routes. By default, set to none - all admin routes will be available without authentication |
|
auth.cookieName |
Object |
<optional> |
adminBro | When auth strategy is set to 'session', this will be the name of the cookie |
auth.cookiePassword |
Object |
<optional> |
cookie password for session strategy |
|
auth.isSecure |
Object |
<optional> |
false | if cookie should be accessible only via HTTPS, default to false |
AdminBro instance
Example
const AdminBroPlugin = require('@admin-bro/hapi')
const Hapi = require('hapi')
// see AdminBro documentation on database setup.
const yourDatabase = require('your-database-setup-file')
const ADMIN = {
email: '[email protected]',
password: 'password',
}
const adminBroOptions = {
resources: [yourDatabase],
auth: {
authenticate: (email, password) => {
if (ADMIN.email === email && ADMIN.password === password) {
return ADMIN
}
return null
},
strategy: 'session',
cookieName: 'adminBroCookie',
cookiePassword: process.env.COOKIE_PASSWORD || 'makesurepasswordissecure',
isSecure: true, //only https requests
},
}
const server = Hapi.server({ port: process.env.PORT || 8080 })
const start = async () => {
await server.register({
plugin: AdminBroPlugin,
options: adminBroOptions,
})
await server.start()
}
start()
# static renderLogin()
Renders login page by simply invoking AdminBro.renderLogin