Issue with deployment and login loop due to lack of admin permission
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 deploySometimes 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@latest3. 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 sanityMake 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/sanityMake 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 deployThis 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!
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.