Admin Setup
Enable the admin module, server config, and generated client config.
Setting up the admin panel requires three steps: add the module, create config/admin.ts, and expose the generated client config.
1. Install
bun add @questpie/admin2. Runtime Config
import { runtimeConfig } from "questpie/app";
export default runtimeConfig({
app: { url: process.env.APP_URL || "http://localhost:3000" },
db: { url: process.env.DATABASE_URL },
secret: process.env.APP_SECRET,
});The admin module contributes its codegen plugin automatically, including config/admin.ts and blocks/ discovery.
3. Module
Add adminModule to your modules:
import { adminModule } from "@questpie/admin/modules/admin";
import { auditModule } from "@questpie/admin/modules/audit";
export default [adminModule, auditModule] as const;| Module | Provides |
|---|---|
adminModule | User collection, auth pages, admin UI |
auditModule | Audit log collection, timeline widget |
Admin User Contract
adminModule includes the starter auth model and owns the canonical Better Auth user collection shape used by admin setup and login guards. That contract includes user.role with at least admin and user values.
The built-in setup route checks whether any user has role = "admin", and the admin UI guard expects session.user.role === "admin". Do not create a replacement collection("user") from scratch in an app using adminModule; merge starterModule.collections.user and extend it if custom user fields or layout are needed.
4. Admin Config
Create the admin config file:
import { adminConfig } from "#questpie/factories";
export default adminConfig({
branding: {
name: "My App Admin",
},
sidebar: {
sections: [
{ id: "overview", title: { en: "Overview" } },
{ id: "content", title: { en: "Content" } },
],
items: [
{
sectionId: "overview",
type: "link",
label: { en: "Dashboard" },
href: "/admin",
icon: { type: "icon", props: { name: "ph:house" } },
},
{
sectionId: "content",
type: "collection",
collection: "posts",
},
],
},
});5. Run Codegen
bunx questpie generate6. Admin Client (Generated)
The admin client config is auto-generated by codegen. No manual builder setup is needed.
Create the client module registry, then run codegen:
export { default } from "@questpie/admin/client-module";After running bunx questpie generate, a pre-built admin config is emitted at questpie/admin/.generated/client.ts.
You can re-export it for convenience:
export { default as admin } from "./.generated/client";7. Mount the Admin
Add the admin routes to your app. The admin panel is typically served at /admin:
import { AdminRouter } from "@questpie/admin/client";
import { admin } from "@/questpie/admin/admin";
export default function AdminPage() {
return <AdminRouter admin={admin} />;
}