Class

AdminJS

AdminJS(options)

Main class for AdminJS extension. It takes AdminJSOptions as a parameter and creates an admin instance.

Its main responsibility is to fetch all the resources and/or databases given by a user. Its instance is a currier - injected in all other classes.

Constructor

# new AdminJS(options)

Parameters:
Name Type Description
options AdminJSOptions

Options passed to AdminJS

View Source adminjs/src/adminjs.ts, line 39

Example
const AdminJS = require('adminjs')
const admin = new AdminJS(AdminJSOptions)

Classes

AdminJS

Members

ActionsMap

# static ACTIONS

List of all default actions. If you want to change the behavior for all actions like:

list, edit, show, delete and bulkDelete you can do this here.

View Source adminjs/src/adminjs.ts, line 336

Example

Modifying accessibility rules for all show actions

const { ACTIONS } = require('adminjs')
ACTIONS.show.isAccessible = () => {...}
string

# static VERSION

AdminJS version

View Source adminjs/src/adminjs.ts, line 342

# ACTIONS

List of all default actions. If you want to change the behavior for all actions like:

list, edit, show, delete and bulkDelete you can do this here.

View Source adminjs/src/adminjs.ts, line 53

Example

Modifying accessibility rules for all show actions

const { ACTIONS } = require('adminjs')
ACTIONS.show.isAccessible = () => {...}
AdminJSOptions

# options

Options given by a user

View Source adminjs/src/adminjs.ts, line 72

Array.<BaseResource>

# resources

List of all resources available for the AdminJS.

They can be fetched with the AdminJS#findResource method

View Source adminjs/src/adminjs.ts, line 67

# VERSION

AdminJS version

View Source adminjs/src/adminjs.ts, line 57

Methods

# static bundle(src, componentNameopt) → {String}

Requires given `.jsx/.tsx` file, that it can be bundled to the frontend.

It will be available under AdminJS.UserComponents[componentId].

Parameters:
Name Type Attributes Description
src String

Path to a file containing react component.

componentName OverridableComponent <optional>

name of the component which you want to override

View Source adminjs/src/adminjs.ts, line 440

componentId - uniq id of a component

String
Examples

Passing custom components in AdminJS options

const adminJsOptions = {
  dashboard: {
    component: AdminJS.bundle('./path/to/component'),
  }
}

Overriding AdminJS core components

// somewhere in the code
AdminJS.bundle('./path/to/new-sidebar/component', 'SidebarFooter')

# static registerAdapter(options) → {void}

Registers various database adapters written for AdminJS.
Parameters:
Name Type Description
options Object
Database Class.<BaseDatabase>

subclass of BaseDatabase

Resource Class.<BaseResource>

subclass of BaseResource

View Source adminjs/src/adminjs.ts, line 363

void
Example
const AdminJS = require('adminjs')
const MongooseAdapter = require('adminjs-mongoose')
AdminJS.registerAdapter(MongooseAdapter)

# findResource(resourceId) → {BaseResource}

Returns resource base on its ID
Parameters:
Name Type Description
resourceId String

ID of a resource defined under BaseResource#id

View Source adminjs/src/adminjs.ts, line 410

When resource with given id cannot be found

Error

found resource

BaseResource
Example
const User = admin.findResource('users')
await User.findOne(userId)

# async initialize() → {Promise.<void>}

Initializes AdminJS instance in production. This function should be called by

all external plugins.

View Source adminjs/src/adminjs.ts, line 371

Promise.<void>

# async renderLogin(options) → {Promise.<string>}

Renders an entire login page with email and password fields

using Renderer.

Used by external plugins

Parameters:
Name Type Attributes Description
options Object
action String

Login form action url - it could be '/admin/login'

errorMessage String <optional>

Optional error message. When set, renderer will print this message in the form

View Source adminjs/src/adminjs.ts, line 397

HTML of the rendered page

Promise.<string>

# resolveBabelConfigPath() → {void}

Resolve babel config file path,

and load configuration to this.options.bundler.babelConfig.

View Source adminjs/src/adminjs.ts, line 417

void

# async watch() → {Promise.<never>}

Watches for local changes in files imported via AdminJS.bundle.

It doesn't work on production environment.

View Source adminjs/src/adminjs.ts, line 380

Promise.<never>

Type Definitions

object

# CurrentAdmin

Currently logged in admin.

Usage with TypeScript

import { CurrentAdmin } from 'adminjs'
Properties:
Name Type Attributes Description
email string

Admin has one required field which is an email

title string <optional>

Optional title/role of an admin - this will be presented below the email

avatarUrl string <optional>

Optional url for an avatar photo

id string <optional>

Id of your admin user

{...} any

Also you can put as many other fields to it as you like.

View Source adminjs/src/current-admin.interface.ts, line 4

Union

# OverridableComponent

Name of the components which can be overridden by AdminJS.bundle. It currently following

components can be override:

  • LoggedIn
  • NoRecords
  • Sidebar
  • SidebarResourceSection
  • SidebarFooter
  • SidebarBranding

View Source adminjs/src/frontend/utils/overridable-component.ts, line 3

object

# UploadedFile

File uploaded via FormData to the backend.
Properties:
Name Type Description
size number

The size of the uploaded file in bytes., this property says how many bytes of the file have been written to disk yet.

path string

The path this file is being written to.

type string

The mime type of this file, according to the uploading client.

name string | null

The name this file had according to the uploading client.

View Source adminjs/src/backend/utils/uploaded-file.type.ts, line 4