See how we built our intranet. Live + Q&A, June 30

How to authenticate Sanity client to fetch unpublished drafts in next-sanity?

24 repliesLast updated: Nov 30, 2025

Hi I’m using
next-sanity
real-time preview and it’s working fabulously (thank you!) Unfortunately it’s only working on published drafts, is there a way to authenticate the sanity client to include drafts when running
client.fetch
?
AI Update

Great! I can see you're using the real-time preview features. To access draft content with client.fetch, you need to set the correct perspective parameter on your Sanity client. The previewDrafts perspective is what you're looking for.

When you configure your Sanity client, you can set the perspective to previewDrafts which will include draft content in your queries. Here's how to do it:

import { createClient } from 'next-sanity'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  apiVersion: '2024-01-01',
  useCdn: false, // Important: disable CDN for draft content
  perspective: 'previewDrafts', // This includes drafts
  token: process.env.SANITY_API_READ_TOKEN, // Required for draft access
})

The key points are:

If you're using the modern Live Content API with defineLive, you can pass the token in your configuration:

import { defineLive } from 'next-sanity/live'

export const { sanityFetch, SanityLive } = defineLive({
  client,
  serverToken: process.env.SANITY_API_READ_TOKEN,
  browserToken: process.env.NEXT_PUBLIC_SANITY_API_READ_TOKEN,
})

Then ensure your client has the previewDrafts perspective set, especially when working with Draft Mode in your Next.js app.

Note about API versions: As of the recent API version 2025-02-19, the default perspective changed to published, so explicitly setting the perspective is now more important than ever if you want to see draft content.

The available perspectives are:

Show original thread
24 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions