Draft mode and request isolation
What you need to know
Draft Mode allows an editor to preview content that would otherwise be served from a published static version. It changes the rendering context through a bypass cookie. It is not a user identity, an authorization role, or permission to expose unpublished data.
By the end, you can: explain preview scope; design access checks.
Read preview state (app/preview-status/page.tsx)
import { draftMode } from "next/headers";export default async function PreviewStatus() { const { isEnabled } = await draftMode(); return <main><h1>Preview status</h1><p>{isEnabled ? "Preview requested" : "Published mode"}</p></main>;}Expected behavior (not framework-tested): The fixture displays only the mode flag, not confidential draft content. A normal request without the bypass cookie displays Published mode.
How it works
A preview flow needs a verified editor session, a resource-level access decision, a validated destination and a supported context for enabling or disabling the bypass cookie. The content read itself must enforce authorization every time. Do not turn an arbitrary query string into a redirect target or a draft selector. Avoid persisting private drafts in a shared cache. The documented bypass cookie value changes with each new next build. Do not treat it as a long-lived credential or substitute for editor-session revocation. Test preview after a new build and recheck permission on every private read. The fixture intentionally contains no enable endpoint or real authentication service; use a conceptual access model to design the gate before implementing it.
Model a preview read decision (pure policy worksheet, not authentication)
type PreviewInput = { mode: boolean; verifiedEditor: boolean; canRead: boolean };export function mayReadDraft(input: PreviewInput) { return input.mode && input.verifiedEditor && input.canRead;}Expected behavior (not framework-tested): Only three true decisions permit a draft read. In a real app, verifiedEditor and canRead are computed from a trusted server-side identity and policy, never accepted as client assertions.
Common mistake
Do not make isEnabled the sole condition for reading a draft. Do not place preview tokens or secrets in example links or logs. For shared caching, even a correct editor-only render does not prove a separate anonymous request cannot receive the same data.
Practice and verification
Design a test matrix for anonymous visitor, editor with permission, editor without permission, disabled preview, and expired session. Assert private fixture markers are absent from every denied response. Explain how preview disabling and session revocation differ.
Scope: App Router, proposed Next.js 16.x, Cache Components disabled for these labs. Snippets assume a reviewed TypeScript app and are static examples; framework behavior has not been executed. Exact supported patch and dependency set must be verified before running.
Further reading: Draft · Data Security · Auth · Fetch