Sanity Library Reference Docs
    Preparing search index...

    Function defineEnableDraftMode

    • Sets up an API route for enabling draft mode, can be paired with the previewUrl.previewMode.enable in sanity/presentation. Can also be used with sanity-plugin-iframe-pane.

      When the preview loads in a cross-site iframe (Presentation Tool), draft-mode cookies are set with the CHIPS Partitioned attribute so Safari 18.4+ stores them despite third-party cookie blocking. Top-level / same-site requests keep unpartitioned cookies so draftMode().disable() continues to work.

      Parameters

      Returns EnableDraftMode

      // src/app/api/draft-mode/enable/route.ts

      import { defineEnableDraftMode } from "next-sanity/draft-mode";
      import { client } from "@/sanity/lib/client";

      export const { GET } = defineEnableDraftMode({
      client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),
      });