Sanity Session Does Not Match Project Host Error After Login/Logout

3 repliesLast updated: Nov 29, 2025

I have stumble upon a weird bug about my session not matching project host. Anyone knows why? I have used
sanity logout
and
sanity login
and it still doesn’t work
Error: Session does not match project host
    at Object.getRemoteGraphQLSchema (.../node_modules/gatsby-source-sanity/lib/util/remoteGraphQLSchema.js:25:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
AI Update

The "Session does not match project host" error with gatsby-source-sanity is typically caused by using an authentication token that belongs to a different Sanity project than the one configured in your Gatsby setup.

Running sanity logout and sanity login won't fix this issue because those commands manage your CLI session tokens, not the API tokens used by gatsby-source-sanity. The problem is specifically about a mismatch between:

The solution is to generate a new API token for the correct project:

Your gatsby-config.js should look something like:

{
  resolve: 'gatsby-source-sanity',
  options: {
    projectId: 'abc123', // Make sure this matches your project
    dataset: 'production',
    token: 'your-new-token-here', // Use the newly generated token
  }
}

This is a common issue that happens when you're working with multiple Sanity projects and accidentally mix up tokens between them. The error message is thrown from the gatsby-source-sanity plugin when it tries to fetch your GraphQL schema and detects that the authentication token doesn't belong to the project you're trying to access.

Make sure the projectId in your config matches the project for which you generated the token, and you should be good to go!

Show original thread
3 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions