🎤 Builder Talk: The Story Behind Lady Gaga’s Digital Experience – Register now

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
Espen Hovlandsdal
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– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?

Related contributions

Turbo Start Sanity
- Template

The battle-tested Sanity template that powers Roboto Studio's websites

Go to Turbo Start Sanity

Schema UI - Next.js Sanity Starter
- Template

A Next.js starter template with Next.js 15, Tailwind CSS, shadcn/ui, and Sanity CMS with Live Editing. Get production-ready React components with matching Sanity schemas and queries. Build dynamic pages faster while keeping full control over customization.

Serge Ovcharenko
Go to Schema UI - Next.js Sanity Starter

The Swaddle
- Made with Sanity

A new brand identity to represent a more mature company, to signify The Swaddle’s evolution from publisher to production house, combined with an easier to navigate platform that can surface multiple content types - drawing readers through The Swaddle’s content offering.

Nightjar
Go to The Swaddle