Joint session with Vercel: How to build intelligent storefronts (May 15th)

CORS Error: No Access-Control-Allow-Origin Header in React App with Sanity

3 repliesLast updated: Nov 29, 2025

Hi, sorry I'm still having a CORS error (No-access-control-origin header is present) in my local environment that I can't fix, so data isn't being connected from Sanity to my react app. I've updated my images and code, here is a list of 10 images showing errors, code, file directory etc (with a quick description for each). Wasn't entirely sure what to include. Been stuck on this issue for a week now and I have a deadline coming up so super appreciate any help!
AI Update

I can help you fix this CORS error! This is a common issue when connecting Sanity to React apps. Let me walk you through the solution step by step.

The "No 'Access-Control-Allow-Origin' header is present" error means your React app's domain isn't authorized to access your Sanity project's data. Here's how to fix it:

Add Your Domain to CORS Origins

Critical Details

Protocol matters: http://localhost:3000 and https://localhost:3000 are different origins. Make sure you add the exact URL showing in your browser's address bar.

Port number matters: localhost:3000 is different from localhost:3001. Check which port your React app actually runs on.

Common Configuration Issues

If you're using a token with your Sanity client, your configuration should look like this:

import {createClient} from '@sanity/client'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'production',
  useCdn: false, // set to false for development
  apiVersion: '2024-01-01',
  token: 'your-token', // only if needed
})

Important: If you have a token in your client config, you must enable "Allow credentials" for that CORS origin in the management dashboard. This is the most common mistake that causes CORS errors even after adding the origin.

Additional Troubleshooting

Asset-Specific CORS Issues

Note that CORS settings in the management dashboard apply to the Data API but not automatically to the Asset CDN. If you're specifically having issues fetching assets (images, files), that may require additional configuration.

Since you've been stuck on this for a week with a deadline approaching, I'd recommend starting fresh with these exact steps. The solution is almost always that the origin isn't added correctly or the "Allow credentials" checkbox isn't enabled when using tokens. Make sure you're using client.fetch() correctly with your Authorization header if you have a token, and verify the exact localhost URL and port your React app is running on!

Show original thread
3 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