Reputation: 87
I tried fetching data from Sanity in client component Next 13 using both a client fetching library and vanilla react. It shows this error:
Access to XMLHttpRequest at 'https://rc70arjs.api.sanity.io/v2021-10-21/data/query/production?query=*%5B_type+%3D%3D+%22user%22%5D' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This is my client config:
const client = createClient({
projectId: 'rc70arjs',
dataset: 'production',
apiVersion: '2021-10-21',
useCdn: true
});
Upvotes: 0
Views: 520
Reputation: 2960
Please add CORS configuration to sanity.
Via your management console
To add a CORS origin from your management console:
Via the command line interface
To add a CORS origin from the CLI:
cors add [ORIGIN]
, where [ORIGIN]
meets the requirements listed aboveYou can confirm your origin was added with the statement CORS origin added successfully
or by consulting the list returned by the command sanity cors list.
More details at Sanity Docs
Upvotes: 1