Configuration
Environment Variables
All configuration is done through environment variables. Create a .env file in the fastify-admin/ directory (never commit this file):
# DatabaseDB_HOST=localhostDB_PORT=5432DB_NAME=fastifyadminDB_USER=postgresDB_PASSWORD=password
# JWT — change this to a long random string in production!ADMIN_JWT_SECRET=change-me-in-production
# Admin panel name (shown in the sidebar and browser tab)ADMIN_NAME=My App Admin
# Port the API listens onADMIN_PORT=3001
# Used for OAuth redirect URLsADMIN_BASE_URL=http://localhost:3001
# Allow users to register themselves (default: false)ADMIN_SIGNUP_ENABLED=false
# Enable MFA (users can't toggle MFA on their account when false)ADMIN_MFA_ENABLED=false
# Require email OTP verification on signup before the user can log inADMIN_EMAIL_VERIFICATION=false
# Email (needed for MFA codes and signup verification)SMTP_HOST=smtp.gmail.comSMTP_PORT=587SMTP_USER=you@gmail.comSMTP_PASS=your-app-passwordSMTP_FROM=you@gmail.comSMTP_SECURE=false
# OAuth — GoogleGOOGLE_CLIENT_ID=GOOGLE_CLIENT_SECRET=
# OAuth — GitHubGITHUB_CLIENT_ID=GITHUB_CLIENT_SECRET=
# OAuth — MicrosoftMICROSOFT_CLIENT_ID=MICROSOFT_CLIENT_SECRET=Plugin Options (in dev.ts)
When you register the admin plugin you can pass these options:
await app.register(fastifyAdmin, { // Required: your MikroORM instance orm,
// Display name shown in the sidebar header name: 'My App Admin',
// Allow users to sign up themselves (default: false, or set ADMIN_SIGNUP_ENABLED=true) signup: false,
// Entity names that are treated as "security" entities // They are hidden from the main nav and shown in the Security section securityEntities: ['user', 'role', 'permission'],
// URL used for OAuth redirect (must match what you set in the OAuth provider) appBaseUrl: 'http://localhost:3001',
// Per-entity view configuration (see adding-entities.md) views: { post: { ... }, product: { ... }, },});Database Configuration
Database settings live in fastify-admin/src/mikro-orm.config.ts. Everything reads from environment variables so you never hardcode credentials:
export default defineConfig({ dbName: process.env.DB_NAME ?? 'fastifyadmin', host: process.env.DB_HOST ?? 'localhost', port: parseInt(process.env.DB_PORT ?? '5432'), user: process.env.DB_USER ?? 'postgres', password: process.env.DB_PASSWORD ?? 'password', // ...});OAuth Setup
To enable “Continue with Google/GitHub/Microsoft” buttons, you need to:
- Create an OAuth app in the provider’s developer console
- Set the redirect URL to
http://localhost:3001/api/auth/{provider}/callback - Copy the client ID and secret into your
.env
- Go to Google Cloud Console → APIs & Services → Credentials
- Create an OAuth 2.0 Client ID
- Set redirect URI:
http://localhost:3001/api/auth/google/callback
GitHub
- Go to GitHub → Settings → Developer settings → OAuth Apps
- Set callback URL:
http://localhost:3001/api/auth/github/callback
Microsoft
- Go to Azure Portal → App registrations
- Set redirect URI:
http://localhost:3001/api/auth/microsoft/callback
Once the environment variables are set, the login and signup pages automatically show the corresponding buttons.
Disabling Features
Disable self-signup (admin-only user creation):
ADMIN_SIGNUP_ENABLED=falseMake an entity read-only (no create/edit/delete):
views: { order: new class extends EntityView { permissions() { return { create: false, edit: false, delete: false } } },}Hide an entity from the sidebar:
views: { auditLog: { sidebar: false, },}