Sanity GraphQL deploy fails with HTTP 401 "Session not found" error

9 replies
Last updated: Aug 5, 2020
hey all - back after a brief break while working on other things. tried to fire up my studio, and when attempting to deploy graphql i get errors
Error: Request returned HTTP 401

running
sanity graphql list
gives me this error:
Unauthorized - Session not found.

any ideas?
AI Update

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:

  1. Session timeout - Your CLI session may have expired while you were away
  2. Invalid token - If you have a SANITY_AUTH_TOKEN environment variable set, it might be invalid
  3. Temporary issue - Sometimes it's just a hiccup, and retrying the command works
  4. 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.json and sanity.config.js/ts files are)
  • Verify your project has the correct projectId and dataset configured in sanity.cli.js or sanity.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 thread
9 replies
maybe the session expired but sanity still thinks you're logged in? try
sanity logout
then
sanity login
?
are you saying log in/out of the
manage
site?
Oh, I just meant from the CLI regarding the
unauthorized
response for
sanity graphql list
oh, never done that before
how do i do that?
in your studio directory in the terminal just run
sanity login
yep! that was 100% it!
thank you!
awesome, np! πŸ‘

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.

Was this answer helpful?