
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see you're trying to set up preview functionality with Sanity Studio and Next.js in separate repositories, following the nextjs-live-preview guide and the preview-content-on-site docs.
First, let me clarify something important: both guides you're following are for Sanity Studio v3 with the Presentation tool. When you mentioned "using v2 in sanity studio," I want to make sure we're on the same page about your actual Studio version.
Run this command in your Studio repository to confirm which version you have:
npm list sanityIf you see sanity@2.x.x, you have Studio v2. If you see sanity@3.x.x or higher, you have Studio v3.
Studio v2 does not have the Presentation tool that those guides describe. The Visual Editing workflow with real-time preview, click-to-edit overlays, and the embedded iframe preview requires Studio v3.
Since you can't see preview content locally, here are the most common issues with separate repository setups:
With Studio and Next.js on different ports/domains, you need to configure CORS:
http://localhost:3000)The Presentation tool needs to activate draft mode in your Next.js app. Check:
In your Studio's sanity.config.ts:
import { presentationTool } from 'sanity/presentation'
export default defineConfig({
// ... other config
plugins: [
presentationTool({
previewUrl: {
draftMode: {
enable: '/api/draft', // This should match your Next.js API route
},
},
}),
],
})In your Next.js app, you need an API route (e.g., /pages/api/draft.ts for Pages Router):
import { validatePreviewUrl } from '@sanity/preview-url-secret'
import type { NextApiRequest, NextApiResponse } from 'next'
import { createClient } from 'next-sanity'
const client = createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
apiVersion: '2024-01-01',
useCdn: false,
token: process.env.SANITY_API_READ_TOKEN!,
})
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
const { isValid, redirectTo = '/' } = await validatePreviewUrl(client, req.url!)
if (!isValid) {
return res.status(401).send('Invalid secret')
}
res.setDraftMode({ enable: true })
res.writeHead(307, { Location: redirectTo })
res.end()
}You need a viewer token for stega encoding to work:
.env.local file as SANITY_API_READ_TOKENYour Sanity client needs to be configured for preview with the previewDrafts perspective and stega encoding:
import { createClient } from '@sanity/client'
export function getClient(previewToken?: string) {
return createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
apiVersion: '2024-01-01',
useCdn: !previewToken,
perspective: previewToken ? 'previewDrafts' : 'published',
stega: {
enabled: previewToken ? true : false,
studioUrl: 'http://localhost:3333', // Your Studio URL
},
token: previewToken,
})
}You need to use useLiveQuery from next-sanity/preview to see real-time updates:
import { useLiveQuery } from 'next-sanity/preview'
export default function PostPreview({ post, params }) {
const [data] = useLiveQuery(post, POST_QUERY, params)
return <Post post={data} />
}If you confirmed you have Studio v2, you'll need to upgrade to Studio v3 to use those guides. Follow the Studio v3 migration guide. Studio v2 is in maintenance mode and the modern Visual Editing features simply don't exist in v2.
Without seeing the video you mentioned, here's how to diagnose the issue:
/api/draft route?http://localhost:3000/api/draft?slug=/your-page manuallyThe most common issue with separate repositories is the draft mode not activating due to CORS, missing tokens, or incorrect API route configuration.
If you can share specific error messages from your console or clarify your Studio version, I can provide more targeted help!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store