CLI login loop: "You've been logged out" error during sanity deploy

10 replies
Last updated: Dec 2, 2025
Hey all, I have this really bizarre issue with deployment and login.I am stuck in a CLI loop – here’s what happens when I try to deploy:

$ sanity login
? Login type GitHub

Opening browser at <https://api.sanity.io/v1/auth/login/github?type=listen&uuid=5bdfec28f8357d0fef479bed44889d4c&source=cli>

Login successful
$ sanity deploy
✔ Checking project info
✔ Clearing output folder (6ms)
✔ Building Sanity (22224ms)
✔ Building index document (27ms)
✔ Minifying JavaScript bundles (20340ms)
✔ Verifying local content
✖ Deploying to Sanity.Studio
Error: You've been logged out. Log back in again with "sanity login"
    at onError (/usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:1902:1974)
    at /usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2820:241
    at Array.reduce (<anonymous>)
    at /usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2820:225
    at /usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2808:965
    at /usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2808:1028
    at x (/usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2856:1442)
    at /usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:2856:2885
    at u.<anonymous> (/usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js:1554:181)
So I
1. login,
2. deploy,
3. deploy fails because i’m logged out
4. I log in again,
repeat.

What is happening here?
AI Update

I understand how frustrating this login loop is! This is an authentication issue with the Sanity CLI where the authentication state isn't being maintained between the login and deploy commands.

What's happening:

The CLI successfully authenticates when you run sanity login, but for some reason that authentication isn't being recognized when sanity deploy runs. This creates the endless loop where you're technically logged in, but the deploy command can't access or verify that authentication.

Here's how to fix it:

1. Try logging out first, then back in:

sanity logout
sanity login
sanity deploy

Sometimes the authentication state gets corrupted, and a clean logout/login cycle can reset it properly.

2. Update your CLI:

Sometimes this is caused by a CLI bug that's been fixed in newer versions:

npm uninstall -g @sanity/cli
npm install -g @sanity/cli@latest

3. Check for Node version managers:

If you're using nvm or another Node version manager, make sure you're consistently using the same Node version. The CLI might store authentication in one Node environment but you're running deploy from another. Try running:

which node
which sanity

Make sure both are coming from the same Node installation.

4. Check file permissions:

The CLI stores authentication credentials locally. If there are permission issues with the config directory, it might successfully write during login but fail to read during deploy. On Unix systems, check:

ls -la ~/.config/sanity

Make sure you have read/write permissions on the config files.

5. For CI/CD or automated deployments:

If you're deploying as part of a CI/CD pipeline, the official documentation for automated deployments recommends using the SANITY_AUTH_TOKEN environment variable:

  • Go to manage.sanity.io
  • Navigate to your project → API → Tokens
  • Create a new token with deploy/write permissions
  • Use it when deploying:
SANITY_AUTH_TOKEN=your-token-here sanity deploy

This approach is specifically designed for automated deployment workflows with GitHub Actions and other CI/CD platforms.

The most common fix is the logout/login cycle (option #1) combined with updating the CLI (option #2). If you're still stuck after trying these, it's worth checking if there are any corporate proxies, VPNs, or network policies that might be interfering with the authentication flow during the deploy step specifically.

Let me know which solution works for you!

Show original thread
10 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.

Was this answer helpful?