Sanity GraphQL deploy fails with HTTP 401 "Session not found" error
Hey! This is a classic authentication issue with the Sanity CLI. Based on the official CLI errors documentation, the "Unauthorized - Session not found" error can happen for a few different reasons when running commands like sanity graphql deploy or sanity graphql list.
Quick Fix
The most common solution is to log out and log back in with the CLI:
npx sanity logout
npx sanity login(Or use pnpm dlx, yarn dlx, or bunx depending on your package manager)
Why This Happens
According to the Sanity docs, this error can occur because:
- Session timeout - Your CLI session may have expired while you were away
- Invalid token - If you have a
SANITY_AUTH_TOKENenvironment variable set, it might be invalid - Temporary issue - Sometimes it's just a hiccup, and retrying the command works
- User authentication issue - Something went wrong with your logged-in user
Where CLI Stores Auth
The Sanity CLI stores your authentication session locally (typically in ~/.config/sanity on Mac/Linux). When you've been away for a while, this session can expire or become invalid.
Additional Things to Check
- Make sure you're running the command from within your Sanity project directory (where your
package.jsonandsanity.config.js/tsfiles are) - Verify your project has the correct
projectIdanddatasetconfigured insanity.cli.jsorsanity.cli.ts - If you're using an authentication token via environment variables, double-check that it's still valid
The logout/login cycle should refresh your session and get you back up and running. Welcome back! π
Show original thread9 replies
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.