Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences β†’

Hey guys, I'm trying to use the `@sanity/client` package from a Netlify function but am getting an error only in production, not locally with netlify dev: `Sanity error:ClientError:...

3 replies
Last updated: Apr 25, 2020

Hey guys, I'm trying to use the

@sanity/client
package from a Netlify function but am getting an error only in production, not locally with netlify dev:
Sanity error: ClientError: Unauthorized - Session not found

I've created an API token and am passing it with the sanity client calls, so think that the error may have something to do with my CORS Origins configuration? I allowed credentials for a netlify domain like
<https://bloopity-blopity-1n23io.netlify.app>
does that look right? Any help would be much appreciated!

Apr 24, 2020, 8:45 PM

No, CORS should give a different error (and isn't in play for server-server communication, which it sounds like this is - if it's a netlify function).
Sounds like the token isn't passed through properly. Are you sure it's being set?

Apr 24, 2020, 9:17 PM

Thanks

user Z
you got me looking in the right place. Made a new API key just to double check, then ran some tests and I think it's all good now? Sorry to bother but I appreciate the magic friday luck

Apr 24, 2020, 11:40 PM

Happy friday πŸŽ‰ Glad you got it working πŸ™‚

Apr 25, 2020, 12:21 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.