Unauthorized error when running npm create sanity@latest -y command

3 replies
Last updated: May 10, 2024
Hi folks - running
npm create sanity@latest -y
- gives unauthorized error as I am not logged in. How am I supposed to be logged in when package is not even installed?
May 10, 2024, 10:32 PM
Can you please paste a snippet of exactly what you’re seeing in the terminal? I’m not able to reproduce whether logged in or not and whether the CLI is already installed or not.
May 10, 2024, 10:39 PM
greggevorkyan@MacBook-Pro-6 modernbanc-sanity % npm -y create sanity@latest
You're setting up a new project!
We'll make sure you have an account with <http://Sanity.io|Sanity.io>. Then we'll
install an open-source JS content editor that connects to
the real-time hosted API on <http://Sanity.io|Sanity.io>. Hang on.

Press ctrl + C at any time to quit.

Prefer web interfaces to terminals?
You can also set up best practice Sanity projects with
your favorite frontends on <https://www.sanity.io/templates>

Looks like you already have a Sanity-account. Sweet!

✖ Fetching existing projects

Error: Failed to communicate with the Sanity API:
Unauthorized - Session not found. You may need to login again with sanity login.
For more information, see <https://docs.sanity.io/help/cli-errors>.
    at getOrCreateProject (~/.npm/_npx/67a0730928194b24/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:44559:29)
    at async getProjectDetails (~/.npm/_npx/67a0730928194b24/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:44521:21)
    at async initSanity (~/.npm/_npx/67a0730928194b24/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:44316:108)
greggevorkyan@MacBook-Pro-6 modernbanc-sanity % npm create sanity@latest -y
You're setting up a new project!
We'll make sure you have an account with <http://Sanity.io|Sanity.io>. Then we'll
install an open-source JS content editor that connects to
the real-time hosted API on <http://Sanity.io|Sanity.io>. Hang on.

Press ctrl + C at any time to quit.

Prefer web interfaces to terminals?
You can also set up best practice Sanity projects with
your favorite frontends on <https://www.sanity.io/templates>

Looks like you already have a Sanity-account. Sweet!

✖ Fetching existing projects

Error: Failed to communicate with the Sanity API:
Unauthorized - Session not found. You may need to login again with sanity login.
For more information, see <https://docs.sanity.io/help/cli-errors>.
    at getOrCreateProject (~/.npm/_npx/67a0730928194b24/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:44559:29)
    at async getProjectDetails (~/.npm/_npx/67a0730928194b24/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:44521:21)
    at async initSanity (~/.npm/_npx/67a0730928194b24/node_modules/@sanity/cli/lib/_chunks-cjs/cli.js:44316:108)
greggevorkyan@MacBook-Pro-6 modernbanc-sanity % npm sanity login           
Unknown command: "sanity"

To see a list of supported npm commands, run:
  npm help
May 10, 2024, 11:09 PM
I just solved it by pre-installing sanity globally with
npm install sanity -g
but I wish it was in the docs.
May 10, 2024, 11:10 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?