Using KeyStatic in the Next.js Supabase SaaS Starter Kit
KeyStatic is a CMS that stores data in a JSON file or on your Github repository. It's the default CMS implementation in Makerkit.
To use Keystatic, you need to set the CMS_CLIENT environment variable to keystatic. This is the default value, so you don't need to do anything.
CMS_CLIENT=keystaticStorage kinds
Keystatic can be used in two ways:
- Local storage: the content is loaded directly from the file system.
- GitHub storage: the content is loaded from a Github repository. This is best for collaborative content editing or if using Cloudflare.
Local storage
Keystatic uses the local storage kind by default. It is easy to get started with and requires no additional setup. Perfect for personal projects.
NEXT_PUBLIC_KEYSTATIC_STORAGE_KIND=local # local, cloud, githubKEYSTATIC_PATH_PREFIX=apps/webNEXT_PUBLIC_KEYSTATIC_CONTENT_PATH=./contentGitHub storage
You can also use Keystatic Cloud or GitHub as the storage kind as remote storage.
If KEYSTATIC_STORAGE_KIND is set to cloud, the following environment variables are required:
NEXT_PUBLIC_KEYSTATIC_STORAGE_KIND=cloudKEYSTATIC_STORAGE_PROJECT=project-idIf KEYSTATIC_STORAGE_KIND is set to github, the following environment variables are required:
NEXT_PUBLIC_KEYSTATIC_STORAGE_KIND=githubNEXT_PUBLIC_KEYSTATIC_STORAGE_REPO=makerkit/next-supabase-saas-kit-turbo-demoKEYSTATIC_PATH_PREFIX=NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH=./contentKEYSTATIC_GITHUB_TOKEN=github_**********************************************KEYSTATIC_PATH_PREFIX=apps/webOf course, you need to replace the NEXT_PUBLIC_KEYSTATIC_STORAGE_REPO and KEYSTATIC_GITHUB_TOKEN with your own values.
GitHub token
The KEYSTATIC_GITHUB_TOKEN is a Github token with read permissions to the repository, which you can generate from the Github Developer Settings in your account.
Note: the Github token must have permissions to read to the repository (for read-only).
GitHub mode
GitHub mode requires the installation of a GitHub app for displaying the admin.
Please refer to the Keystatic documentation for more information.
If your content folder is not at content, you can set the NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH environment variable to the correct path. For example, if your content folder is at data/content, you can set the NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH environment variable as:
NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH=apps/web/data/contentAdding the Keystatic admin to your app
To add the Keystatic admin UI to your app, please run the following command:
turbo gen keystaticYour app will now have a new route at /keystatic where you can manage your content.
Note: your Github token must have permissions to read to the repository (for read-only).
Note: by default, the Keystatic admin is only available in a development environment. For production environments, please add some sort of authentication. For example, use the isSuperAdmin function to check if the user is a super admin and allow them to access the Keystatic admin.
Cloudflare
Cloudflare Workers doesn't send the User-Agent header which the Github API requires, so you need to add a little customization to the fetch global at packages/cms/keystatic/src/keystatic-client.ts:
packages/cms/keystatic/src/keystatic-client.ts
const self = global || globalThis || this;const originalFetch = self.fetch;self.fetch = (input: RequestInfo | URL, init?: RequestInit) => { const requestInit: RequestInit = { ...(init ?? {}), headers: { ...(init?.headers ?? {}), 'User-Agent': 'Cloudflare-Workers', } }; return originalFetch(input, requestInit);}