CircleCI authentication error: How to use Sanity Token instead of login?
You're getting this error because the Sanity CLI needs authentication when running in a CI/CD environment like CircleCI. The sanity graphql deploy command requires authentication, but the interactive sanity login doesn't work in automated environments.
The solution is to use the SANITY_AUTH_TOKEN environment variable. Here's how to set it up:
Steps to fix:
Generate a token in your Sanity project management dashboard:
- Go to your project settings
- Navigate to API settings
- Create a new token with appropriate permissions (you'll need deploy permissions for GraphQL)
Add the token to CircleCI:
- In your CircleCI project settings, go to Environment Variables
- Add a new variable named
SANITY_AUTH_TOKEN - Paste your token as the value
The CLI will automatically use it - no code changes needed! When the
SANITY_AUTH_TOKENenvironment variable is set, the Sanity CLI will use it for authentication instead of requiring an interactive login.
Your CircleCI config should work as-is:
#!/bin/bash -eo pipefail
sanity graphql deploy --dataset=staging --tag default --playgroundAccording to the CLI Configuration documentation:
When you need to run the CLI unattended, like in a CI/CD environment, set the
SANITY_AUTH_TOKENenvironment variable to a token.
Important: Make sure the token you generate has sufficient permissions for deploying GraphQL schemas. You may need a token with "Deploy Studio" or similar permissions depending on your project setup.
Show original thread4 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.