Prompt
How do I let editors preview content before publishing in a headless CMS?
Latest observation
To let editors preview content before publishing in a headless CMS, you usually set up a draft/preview workflow that exposes unpublished content to authenticated editors only.
Typical approach
1. Keep drafts separate from published content
Most headless CMSs support:
- Drafts / unpublished entries
- Published entries
- Sometimes versioning
Editors work on drafts until they’re ready to publish.
2. Add a preview mode in your frontend
Your frontend app should support a route or mode like:
/preview/...?preview=true- a special preview session
When preview mode is active, the frontend fetches draft content instead of only published content.
3. Use a secure preview token or auth check
To prevent public access to drafts, gate preview access with one of these:
- Preview token issued by the CMS
- Editor authentication via login
- Signed URL / JWT with short expiration
The frontend sends this token to the CMS API to request unpublished content.
4. Configure the CMS API for draft access
Many CMS APIs support queries like:
status=draftpublished=falseversion=draftincludeDrafts=true
In preview mode, your frontend uses those parameters; in normal mode, it only requests published content.
5. Redirect editors to the preview URL
In the CMS, add a “Preview” button that:
- Generates the preview link
- Includes a secure token or session
- Opens the frontend page showing the draft
6. Handle cache carefully
If you use CDN or static generation:
- Avoid caching preview responses publicly
- Make sure draft pages are server-rendered or fetched dynamically
- Separate preview and production cache keys
Common implementation patterns
Pattern A: Preview by token
- Editor clicks preview in CMS
- CMS generates a one-time or short-lived token
- Frontend receives token and fetches draft content
- Token expires after a short time
Pattern B: Preview by logged-in editor
- Editor signs into your app/CMS SSO
- Frontend checks user role
- If user is editor, allow draft fetches
Pattern C: Webhook-triggered draft preview
- Editor saves draft
- CMS sends webhook to your app
- App updates preview environment or draft rendering
Example flow
- Editor writes article in CMS
- Clicks Preview
- CMS opens
https://site.com/preview/article-slug?token=abc123 - Frontend validates token with CMS
- Frontend fetches draft content
- Editor sees the article exactly as it will appear when published
Best practices
- Keep preview tokens short-lived
- Restrict preview access to authenticated users
- Never expose draft API endpoints publicly without protection
- Make preview content visually distinct if helpful
- Ensure preview uses the same components/styles as production
If you want, I can show you how to implement this in a specific stack, like Contentful + Next.js, Sanity, Strapi, or Prismic.