How to deploy embedded Sanity Studio and resolve ID error.

12 replies
Last updated: Aug 23, 2023
Hello everyone,
Does anyone know how to deploy embedded sanity studio? I have access to it now running at
http://localhost:3000/studio .
AI Update

Deploying an embedded Sanity Studio in Next.js is straightforward once you understand the routing requirements. Here's how to deploy your embedded studio that's currently running at http://localhost:3000/studio:

Deployment Process

The good news is that deploying an embedded Sanity Studio works the same way as deploying any Next.js application. When you deploy your Next.js app to platforms like Vercel, Netlify, or any other hosting provider, your embedded Studio will deploy along with it automatically.

Key Requirements for Deployment

1. CORS Configuration (Critical!)

You must add your production domain to your Sanity project's CORS origins settings. This is easy to forget but essential:

  • Go to your Sanity project settings (manage.sanity.io)
  • Navigate to API settings
  • Add your production URL (e.g., https://yourdomain.com)
  • Enable "Allow credentials" for authenticated requests

Without this, your Studio won't be able to authenticate users or save content in production.

2. Routing Configuration

Your Studio needs proper routing to handle all sub-routes. According to the next-sanity documentation, if you're using the App Router, your file structure should look like:

app/studio/[[...index]]/page.tsx

This [[...index]] catch-all route ensures all Studio sub-routes (like /studio/desk/post or /studio/structure) are properly handled. Inside this file, you'll have something like:

import { NextStudio } from 'next-sanity/studio'
import config from '@/sanity.config'

export default function StudioPage() {
  return <NextStudio config={config} />
}

The embedding documentation confirms you need to ensure all sub-routes of the basePath redirect to this route.

3. Environment Variables

Make sure your production environment has the required environment variables set:

NEXT_PUBLIC_SANITY_PROJECT_ID=your-project-id
NEXT_PUBLIC_SANITY_DATASET=production

Most hosting platforms (Vercel, Netlify, etc.) have settings pages where you can add these.

4. Styling

Ensure your Studio has proper styling as mentioned in the embedding documentation:

/* Applied to the container where Studio mounts */
#app {
  height: 100vh;
  max-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  overflow: auto;
}

Example: Deploying to Vercel

  1. Push your code to GitHub/GitLab/Bitbucket
  2. Connect your repository to Vercel
  3. Add environment variables in Vercel's project settings:
    • NEXT_PUBLIC_SANITY_PROJECT_ID
    • NEXT_PUBLIC_SANITY_DATASET
  4. Deploy!

Your Studio will be available at https://yourdomain.com/studio

Example: Deploying to Netlify

Similar process:

  1. Connect your repository
  2. Add environment variables in Site settings → Environment variables
  3. If needed, add a redirect rule in your netlify.toml:
[[redirects]]
  from = "/studio/*"
  to = "/studio"
  status = 200

Verifying Your Deployment

After deployment:

  1. Visit https://yourdomain.com/studio
  2. You should see the Sanity Studio login screen
  3. Sign in with your Sanity account
  4. Verify you can edit and save content

Alternative: Dedicated Studio Hosting

If you prefer not to embed the Studio in your Next.js app, you can also deploy it separately using:

sanity deploy

This hosts it on Sanity's infrastructure at your-project.sanity.studio. This is simpler but gives you less control over customization and integration with your frontend.

The embedded approach you're using is great for having everything in one place and gives you more flexibility for custom integrations!

from your root directory if you use
sanity deploy
from the cli that has worked for me :)
Thank you (Removed Name)) I used
npx sanity deploy
and it was built but I get an error Something wrong with my ID. This is my first Sanity Deployment.
I will be happy to hear any recommendations
I have .env.local file with project id inside as a variable.
I had this issue too — in my sanity.config.js I had to add the dataset and projectId more explicitly like this:
import { projectId, dataset } from “./sanity/env”

export default defineConfig({
projectId: projectId,
dataset: dataset,
basePath: ‘/studio’,
// etc
Let me know if that works. Also, you will need to add those env variables to your Vercel project’s environment variables
Thank you so much, will try. Also I have a question: did you type your deployed project url after you run
sanity deploy
?
Happy to help :) Yes, I did — in my terminal when prompted I added the project url, like sanityproject.sanity.studio (you only need to add that first part before sanity). You can also undeploy and redeploy later if you decide to change the deployed url address.
user C
I undeployed it and checked the url of my deployed project with
/studio
- at the end -&gt; it is working without cms deployment. Only we need to deploy the front-end project itself if we have cms embeded.
Hello
user N
Sorry, yes, now that I read your question again I understand. That’s true that because the studio is embedded, you will need to deploy the frontend to be able to use the
/studio
url route. It was late here when I answered last night 😅 If you would rather have a separate deployment for the studio (not embedded), you can still do that with a separate sanity directory inside your project.
Are you planning to deploy with Vercel? Let me know if you need any help 🙂
Thank you so much) 🙂

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.

Was this answer helpful?