Skip to main content
CMS

CMS configuration

Add the CMS to your site with cmsPlugin(). If you're setting it up for the first time, start with Getting started; the sections below cover the configuration options you'll reach for most often.

Plugin options

Only firebaseConfig is required. Common options include:

  • id: namespaces your site's content in Firestore so multiple sites can share a single Firebase project. Defaults to default.

  • name: the site name shown in the CMS.

  • firebaseConfig: the web app config from the Firebase console.

  • gapi: a Google API key and OAuth client ID for Google Drive and Sheets imports.

  • ai: the models available to Root AI.

  • isUserAuthorized: a custom function to decide whether a user can sign in to the CMS.

See Checks, Notifications and integrations, and Customizing the CMS for the remaining features, or check CMSPluginOptions in the API reference for the full list.

ts
// @/root.config.ts

import {defineConfig} from '@blinkk/root';
import {cmsPlugin} from '@blinkk/root-cms/plugin';

export default defineConfig({
  plugins: [
    cmsPlugin({
      id: 'my-site',
      name: 'My Site',
      firebaseConfig: {
        apiKey: '...',
        authDomain: 'my-project.firebaseapp.com',
        projectId: 'my-project',
        storageBucket: 'my-project.appspot.com',
      },
    }),
  ],
});

Setting up Firebase by hand

root-cms setup handles all of this automatically (see Getting started). If you'd rather configure Firebase yourself:

  1. Create a project in the Firebase console, or add Firebase to an existing Google Cloud project.

  2. Create a Firestore database in Native mode.

  3. Under Authentication, enable the Google sign-in provider. If your site uses a custom domain, add it to the list of authorized domains.

  4. Under Project settings, register a web app and copy its firebaseConfig values into cmsPlugin():

ts
// @/root.config.ts

cmsPlugin({
  id: 'starter',
  name: 'Starter',
  // From Project settings > Your apps in the Firebase console.
  firebaseConfig: {
    apiKey: '...',
    authDomain: 'my-project.firebaseapp.com',
    projectId: 'my-project',
    storageBucket: 'my-project.appspot.com',
  },
}),

Before deploying, replace sessionCookieSecret with a long random string. The server talks to Firestore using application default credentials, so for local development, sign in with the gcloud CLI:

sh
gcloud auth login
gcloud auth application-default login

Then apply the Firestore security rules and add yourself as an admin (see Security rules and roles below).

Security rules and roles

Access to CMS content is controlled by Firestore security rules and a per-site roles map. The quickest way to configure both is with init-firebase, which deploys the rules and grants you the ADMIN role:

sh
pnpm exec root-cms init-firebase --admin=you@example.com

The CMS manages the rules inside the BEGIN ROOT CMS MANAGED RULES block. Place any custom app rules outside that block so they are preserved when you run update-firebase-security-rules or update the rules from Settings → Site Admin.

To apply them manually instead, paste the rules into the Rules tab under Firestore in the Firebase console:

ts
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // === BEGIN ROOT CMS MANAGED RULES (version: 2) — DO NOT EDIT ===
    match /{document=**} {
      allow read, write: if false;
    }

    match /Projects/{project} {
      allow read: if isSignedIn() && userCanRead();
      allow write: if isSignedIn() && userIsAdmin();

      // Default for shared CMS collections (Published, Scheduled, Releases,
      // DataSources, Assets, Translations, etc.).
      match /{collection}/{document=**} {
        allow read: if isSignedIn() && userCanRead();
        allow write: if isSignedIn() && userCanPublish();
      }

      // Draft and collaborative collections (CONTRIBUTOR+).
      match /Collections/{collectionId}/Drafts/{document=**} {
        allow write: if isSignedIn() && userCanEdit();
      }
      match /TranslationsManager/draft/Translations/{document=**} {
        allow write: if isSignedIn() && userCanEdit();
      }
      match /Tasks/{document=**} {
        allow write: if isSignedIn() && userCanEdit();
      }
      match /Counters/tasks {
        allow create, update: if isSignedIn() && userCanEdit();
      }

      // Presence and per-user collections (all signed-in project members).
      match /Viewers/{viewerDoc} {
        allow write: if isSignedIn() && userCanRead();
      }
      match /UserProfiles/{email} {
        allow create, update:
          if isSignedIn() && userCanRead() && request.auth.token.email == email;
      }
      match /Users/{uid} {
        allow create, update:
          if isSignedIn() && userCanRead() && request.auth.uid == uid;
      }
      match /AiChats/{chatId} {
        allow create:
          if isSignedIn() && userCanRead()
          && request.resource.data.createdBy == request.auth.token.email;
        allow update:
          if isSignedIn() && userCanRead()
          && resource.data.createdBy == request.auth.token.email
          && request.resource.data.createdBy == request.auth.token.email;
        allow delete:
          if isSignedIn() && userCanRead()
          && resource.data.createdBy == request.auth.token.email;
      }

      // Role helpers.
      function isSignedIn() {
        return request.auth != null && request.auth.token.email != null;
      }
      function getRoles() {
        return get(/databases/$(database)/documents/Projects/$(project)).data.get('roles', {});
      }
      function hasRole(allowed) {
        let roles = getRoles();
        let email = request.auth.token.email;
        let domain = '*@' + email.split('@')[1];
        return (roles.get(email, '') in allowed) || (roles.get(domain, '') in allowed);
      }
      function userCanRead() {
        return hasRole(['ADMIN', 'EDITOR', 'CONTRIBUTOR', 'VIEWER']);
      }
      function userCanEdit() {
        return hasRole(['ADMIN', 'EDITOR', 'CONTRIBUTOR']);
      }
      function userCanPublish() {
        return hasRole(['ADMIN', 'EDITOR']);
      }
      function userIsAdmin() {
        return hasRole(['ADMIN']);
      }
    }
    // === END ROOT CMS MANAGED RULES ===
  }
}

Next, create a document in Firestore at Projects/<id> (matching your plugin's id) with a roles map that assigns your email to ADMIN. Once you're signed in, you can manage everyone else from the CMS settings page.

The available roles are:

  • ADMIN: full access, including user management and project settings.

  • EDITOR: edit and publish content.

  • CONTRIBUTOR: edit drafts, without permission to publish.

  • VIEWER: read-only access.

You can also grant a role to an entire domain with an entry like *@example.com. Anyone with a verified email on that domain inherits the role, so use it carefully, never with a public email provider, and stick to individual email grants for ADMIN and EDITOR.

Google Drive and Sheets

Features like importing from Google Sheets and Google Drive call Google APIs on the editor's behalf. To turn them on:

  1. In the Google Cloud console, enable the Google Sheets API and Google Drive API.

  2. Create an OAuth client ID (Web application) and an API key.

  3. Pass them to cmsPlugin() as gapi: {clientId, apiKey}, typically via environment variables.

Root AI

Root AI lets editors chat with, draft, and translate content directly in the CMS. Turn it on with the ai option by listing the models editors can pick from along with their API keys. See the v3 migration guide for a full config example.

Custom AI tools and skills

Available as of version 2.4.1.

Root AI can call your own tools alongside the built-in ones for reading and editing docs. Register them in ai.tools. Even though the chat UI runs in the browser, a tool's execute function always runs on the server, so it can safely use API keys and server-only code. Inputs are validated against inputSchema (a Zod schema, or jsonSchema() from ai) before execute runs, and its return value is passed back to the model.

Skills are reusable prompt instructions that editors invoke by typing / and the skill name in chat, like /launch-checklist Pages/home. The model receives the skill's instructions along with anything typed after the command.

ts
// @/root.config.ts

import {cmsPlugin, defineAiSkill, defineAiTool} from '@blinkk/root-cms/plugin';
import {z} from 'zod';

cmsPlugin({
  ai: {
    models: [
      // ...
    ],
    tools: [
      defineAiTool({
        name: 'inventory_lookup',
        description: 'Looks up the stock level for a product SKU.',
        inputSchema: z.object({sku: z.string()}),
        execute: async ({sku}, ctx) => {
          return await fetchStock(sku, {user: ctx.user.email});
        },
      }),
    ],
    skills: [
      defineAiSkill({
        name: 'launch-checklist',
        description: 'Reviews a page against the launch checklist.',
        instructions: 'Read the page with doc_get, then check that ...',
      }),
    ],
  },
});

Set write: true on any tool that mutates data. Write tools are hidden in read-only chat mode and always require editor approval before running, even when auto-apply is on. By default, read tools are available to all roles and write tools are limited to admins, editors, and contributors; set roles to tighten access further. Custom tool names can't conflict with built-in tools like doc_get.

Other Root.js plugins can register tools and skills too by setting rootAi: {tools, skills} on the plugin object (see RootAiPlugin in the API reference).

Scheduled jobs

Scheduled publishing, version history, and a few background tasks rely on a cron job hitting /cms/api/cron.run every few minutes.

Firebase: if you deploy to Cloud Functions for Firebase, export cron from @blinkk/root-cms/functions:

ts
// @/index.ts

import {server} from '@blinkk/root/functions';
import {cron} from '@blinkk/root-cms/functions';

export const www = {
  server: server({mode: 'production'}),
  cron: cron(),
};

Other hosting: on App Engine, Cloud Run, or another host, set up a Cloud Scheduler job (or your platform's equivalent) to request /cms/api/cron.run every few minutes.

Credentials in production

The server connects to Firestore using application default credentials. On Google Cloud (App Engine, Cloud Run, or Cloud Functions), it uses the runtime's default service account, so make sure that account has Firestore access. Everywhere else, point GOOGLE_APPLICATION_CREDENTIALS to a service account key file.

1
2
3
4
5
6
7
8
9
10
11
12
Breakpoint: