Error: You must login first - run "sanity login" at Object.apiClient

4 replies
Last updated: Sep 20, 2020
i tried sanity react and it worked perfectly well but i had to reset my macbook. I reinstalled and got the code repo from github, yarn start worked well, but doing sanity start gives this error
Error: You must login first - run "sanity login"
at Object.apiClient (/usr/local/lib/node_modules/@sanity/cli/bin/sanity-cli.js
:1974:584) at ~/Projects/sanity/sanity-react/mysanityblog/node_modules/@sanity/core/lib/actions/start/startAction.js
:160:41 at Generator.next (<anonymous>)
at asyncGeneratorStep (~/Projects/sanity/sanity-react/mysanityblog/node_modules/@sanity/core/lib/actions/start/startAction.js
:42:103) at _next (~/Projects/sanity/sanity-react/mysanityblog/node_modules/@sanity/core/lib/actions/start/startAction.js
:44:194)
AI Update

The error message is clear - after resetting your MacBook, you need to re-authenticate the Sanity CLI with your account. This is a common issue when setting up a development environment on a fresh machine.

Here's how to fix it:

Run the login command:

sanity login

This will open your browser and prompt you to authenticate with your Sanity account. Once you complete the login, the CLI will store an authentication token locally on your machine.

Where the token is stored: On macOS, Sanity stores your authentication token in ~/.config/sanity/ (typically in a file like tokens.json). When you reset your MacBook, this directory and its contents were wiped, which is why you need to log in again.

After logging in: Once authentication completes, you should be able to run:

sanity start

And your Studio will start up normally.

Important notes:

  • Make sure you're using the same Sanity account that has access to the project in your GitHub repo
  • The yarn start command works because it's running your React frontend, which doesn't need CLI authentication
  • The sanity start command needs authentication because it's starting the Sanity Studio, which requires API access to your project's dataset

If you run into any issues with the login command, make sure you have the Sanity CLI installed globally:

npm install -g @sanity/cli

Or if you're using the CLI from your project's node_modules, you can use:

npx sanity login
Do sanity login first
you mean logging into sanity only. I did logged into sanity but that didn't help.
Run sanity login into your terminal
That worked Thanks.

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?