Skip to content

createAdmin()

ts
import { createAdmin } from "paneljs";
import { prismaAdapter } from "@paneljs/prisma"; // or typeormAdapter from @paneljs/typeorm
import { mount } from "@paneljs/express";

const admin = createAdmin({
  adapter: prismaAdapter({ prisma }),
  auth: { getCurrentUser },
});
admin.register(modelName, modelConfig?);
await mount(app, admin);

createAdmin is the core entry. It returns { register, initialize, registry, config }. Express mounting lives in @paneljs/express.

AdminConfig

OptionTypeDefaultRole
adapterDataAdapterrequiredPrisma, TypeORM, or MikroORM adapter.
authbuilt-in or external auth configrequiredBuilt-in admin credentials/sessions, or an external identity adapter.
basePathstring/adminWhere UI and API are mounted.
siteNamestringPanelJSHeader label in the UI.
databaseProvider"postgresql" | "mysql" | "sqlite" | "sqlserver" | "mongodb"unsetDeprecated, ignored. Each adapter decides search sensitivity.
audit.write(event) => Promise<void>unsetCalled after successful mutations.

Prisma schemaPath is passed to prismaAdapter(), not to createAdmin(). TypeORM and MikroORM read live metadata from an initialized instance instead of a schema path.

mount(app, admin)

Must run after every register. Must be awaited. Throws if:

  • the adapter cannot introspect (missing Prisma schema, uninitialized TypeORM DataSource, version mismatch)
  • a registered model or field does not exist

Mounts, in order: JSON body parser, built-in auth endpoints when enabled, auth on /api, schema route, action routes, CRUD routes, error handler, static UI, SPA fallback.

Types

ts
import type {
  AdminConfig,
  AuthConfig,
  AdminUser,
  AuditConfig,
  AdminAuditEvent,
  ModelConfig,
  DataAdapter,
} from "paneljs";

Released under the MIT License.