Koa
@adminjs/koa
To setup AdminJS panel with Koa you need to have koa installed and required peer dependencies:
$ yarn add koa @koa/router koa2-formidableAfterwards, follow one of the examples below.
Simple
import AdminJS from 'adminjs'
import AdminJSKoa from '@adminjs/koa'
import Koa from 'koa'
const PORT = 3000
const start = async () => {
const app = new Koa()
const admin = new AdminJS({
resources: [],
rootPath: '/admin',
})
const router = AdminJSKoa.buildRouter(admin, app)
app
.use(router.routes())
.use(router.allowedMethods())
app.listen(PORT, () => {
console.log(`AdminJS available at http://localhost:${PORT}${admin.options.rootPath}`)
})
}
start()Install additional dependencies:
Authenticated
To add authentication, you must use AdminJSKoa.buildAuthenticatedRouter instead of AdminJSKoa.buildRouter.
As you may have noticed, the authenticate function compares credentials you submit in the form with a hardcoded DEFAULT_ADMIN object. In your case, you might want to modify authenticate function's logic to compare form credentials against real database objects.
Install additional dependencies:
As you may have noticed, the authenticate function compares credentials you submit in the form with a hardcoded DEFAULT_ADMIN object. In your case, you might want to modify authenticate function's logic to compare form credentials against real database objects.
Last updated
