Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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?