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

Gatsby-Sanity-Source GraphQL Schema Not Found (Error: Session Not Found)

9 replies
Last updated: Apr 17, 2020
Hi! My Gatsby site with the gatsby-sanity-source plugin keeps failing during build on Netlify:

1:35:58 PM: info [sanity] Fetching remote GraphQL schema
1:35:58 PM: error Error: Session not found
1:35:58 PM:     at Object.getRemoteGraphQLSchema (/opt/build/repo/frontend/node_modules/gatsby-source-sanity/lib/util/remoteGraphQLSchema.js:25:15)
1:35:58 PM:     at process._tickCallback (internal/process/next_tick.js:68:7)
Apr 17, 2020, 12:13 PM
Hi Sven! The error indicates that there’s an issue with authentication to Sanity. Are you using environment variables in local development by any chance? These are not picked up by Netlify, not even when placed in a file like
.env.production
.
Instead, you’ll have to add these to Netlify using the instructions on this page:
https://docs.netlify.com/configure-builds/environment-variables/
Apr 17, 2020, 12:21 PM
Thanks for the quick reply
user M
Apr 17, 2020, 12:43 PM
I've added the environment files
Apr 17, 2020, 12:43 PM
And when I do a console.log of
process.env
the variables are visible in the logs of netlify
Apr 17, 2020, 12:44 PM
2:06:53 PM: SANITY_TOKEN:
Apr 17, 2020, 12:45 PM
Assuming you’re loading them correctly with those names on the site itself as well, it might be a different issue in this case. Have you double-checked your CORS origins on manage.sanity.io for the correct URL(s)? (Settings > API > CORS Origins)
Apr 17, 2020, 12:48 PM
OK, it works
Apr 17, 2020, 1:06 PM
Thx for the help
Apr 17, 2020, 1:06 PM
Awesome, Sven! 🚀
Apr 17, 2020, 1:50 PM

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?