Issue with deployment and login loop due to lack of admin permission

10 replies
Last updated: Apr 15, 2021
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!

What happens if you run
sanity logout && sanity login
to reset things, then try another deploy?
same thing – of course it think’s I’m logged out anyway so it says No Login Credentials Found:
$ sanity logout && sanity login
No login credentials found
? Login type GitHub

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

Login successful
(base) Josephs-MBP-2:cms jiovino$ sanity deploy
✔ Checking project info
✔ Clearing output folder (6ms)
✔ Building Sanity (22094ms)
✔ Building index document (28ms)
✔ Minifying JavaScript bundles (20038ms)
✔ 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)
Any chance the terminal command
DEBUG=sanity* sanity deploy
returns anything useful?
Any chance
DEBUG=sanity* sanity deploy
returns anything useful?
Thanks again - it runs into the same issue –1. I login, successfully,
2. it goes partway through the Debug, and then throws the Error: You’ve been logged out.

Perhaps there’s something in these Debug results that could help?
Here’s what happens:

$ sanity login
? Login type GitHub

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

Login successful
(base) Josephs-MBP-2:cms jiovino$ DEBUG=sanity* sanity deploy
  sanity:cli CLI installed at /usr/local/lib/node_modules/@sanity/cli/bin +0ms
  sanity:cli Less than 12 hours since last check, skipping update check +11ms
  sanity:cli Less than 12 hours since last nag, skipping +1ms
  sanity:cli No group found with name "deploy", looking for command +455ms
  sanity:cli Found command in default group with name "deploy" +0ms
  sanity:cli Reading "/Users/jiovino/projects/humility-monolith/cms/sanity.json" +1ms
  sanity:cli Running command "deploy" +2ms
⠋ Checking project info  sanity:client [1] HTTP GET <https://1opf3ch9.api.sanity.io/v1/projects/1opf3ch9> +0ms
  sanity:client [1] Request headers: {
  "Accept": "application/json",
  "User-Agent": "@sanity/client 0.147.0",
  "Authorization": "<redacted>"
} +1ms
⠹ Checking project info  sanity:client [1] Response code: 200 OK +216ms
  sanity:client [1] Response body: {
  "id": "1opf3ch9",
  "displayName": "Humility in the Age of Self-Promotion",
  "studioHost": "humility-cms",
  "isBlocked": false,
  "isDisabled": false,
  "isDisabledByUser": false,
  "metadata": {
    "color": "#325156"
  },
  "maxRetentionDays": 3,
  "activityFeedEnabled": true,
  "createdAt": "2018-08-15T17:30:50.008Z",
  "updatedAt": "2020-12-09T16:29:06.916Z",
  "deletedAt": null,
  "organizationId": null,
  "members": [
    {
      "id": "peqXQMjXy",
      "role": "administrator",
      "isRobot": false
    },
    {
      "id": "pd6rFF7qj",
      "role": "administrator",
      "isRobot": false
    },
    {
      "id": "pFNYNbIiT",
      "role": "write",
      "isRobot": false
    },
    {
      "id": "pfPvr8ZZ8",
      "role": "administrator",
      "isRobot": false
    }
  ],
  "pendingInvites": 0
} +0ms
✔ Checking project info
✔ Clearing output folder (5ms)
✔ Building Sanity (22465ms)
✔ Building index document (27ms)
✔ Minifying JavaScript bundles (20310ms)
✔ Verifying local content
⠋ Deploying to Sanity.Studio  sanity:client [2] HTTP POST <https://1opf3ch9.api.sanity.io/v1/deploy> +44s
  sanity:client [2] Request headers: {
  "Accept": "application/json",
  "User-Agent": "@sanity/client 0.147.0",
  "Authorization": "<redacted>"
} +1ms
⠸ Deploying to Sanity.Studio  sanity:client [2] Response code: 401 Unauthorized +300ms
  sanity:client [2] Response body: {
  "statusCode": 401,
  "error": "Unauthorized",
  "message": "User must be an administrator or a token with deploy rights to perform this operation"
} +0ms
  sanity:client [2] ERROR: Unauthorized - User must be an administrator or a token with deploy rights to perform this operation +1ms
✖ 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)
(base) Josephs-MBP-2:cms jiovino$ 
Thanks again - it runs into the same issue –1. I login, successfully,
2. it goes partway through the Debug, and then throws the Error: You’ve been logged out.

Perhaps there’s something in these Debug results that could help?
Here’s what happens:

$ sanity login
? Login type GitHub

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

Login successful
(base) Josephs-MBP-2:cms jiovino$ DEBUG=sanity* sanity deploy
  sanity:cli CLI installed at /usr/local/lib/node_modules/@sanity/cli/bin +0ms
  sanity:cli Less than 12 hours since last check, skipping update check +11ms
  sanity:cli Less than 12 hours since last nag, skipping +1ms
  sanity:cli No group found with name "deploy", looking for command +455ms
  sanity:cli Found command in default group with name "deploy" +0ms
  sanity:cli Reading "/Users/jiovino/projects/humility-monolith/cms/sanity.json" +1ms
  sanity:cli Running command "deploy" +2ms
⠋ Checking project info  sanity:client [1] HTTP GET <https://1opf3ch9.api.sanity.io/v1/projects/1opf3ch9> +0ms
  sanity:client [1] Request headers: {
  "Accept": "application/json",
  "User-Agent": "@sanity/client 0.147.0",
  "Authorization": "<redacted>"
} +1ms
⠹ Checking project info  sanity:client [1] Response code: 200 OK +216ms
  sanity:client [1] Response body: {
  "id": "1opf3ch9",
  "displayName": "Humility in the Age of Self-Promotion",
  "studioHost": "humility-cms",
  "isBlocked": false,
  "isDisabled": false,
  "isDisabledByUser": false,
  "metadata": {
    "color": "#325156"
  },
  "maxRetentionDays": 3,
  "activityFeedEnabled": true,
  "createdAt": "2018-08-15T17:30:50.008Z",
  "updatedAt": "2020-12-09T16:29:06.916Z",
  "deletedAt": null,
  "organizationId": null,
  "members": [
    {
      "id": "peqXQMjXy",
      "role": "administrator",
      "isRobot": false
    },
    {
      "id": "pd6rFF7qj",
      "role": "administrator",
      "isRobot": false
    },
    {
      "id": "pFNYNbIiT",
      "role": "write",
      "isRobot": false
    },
    {
      "id": "pfPvr8ZZ8",
      "role": "administrator",
      "isRobot": false
    }
  ],
  "pendingInvites": 0
} +0ms
✔ Checking project info
✔ Clearing output folder (5ms)
✔ Building Sanity (22465ms)
✔ Building index document (27ms)
✔ Minifying JavaScript bundles (20310ms)
✔ Verifying local content
⠋ Deploying to Sanity.Studio  sanity:client [2] HTTP POST <https://1opf3ch9.api.sanity.io/v1/deploy> +44s
  sanity:client [2] Request headers: {
  "Accept": "application/json",
  "User-Agent": "@sanity/client 0.147.0",
  "Authorization": "<redacted>"
} +1ms
⠸ Deploying to Sanity.Studio  sanity:client [2] Response code: 401 Unauthorized +300ms
  sanity:client [2] Response body: {
  "statusCode": 401,
  "error": "Unauthorized",
  "message": "User must be an administrator or a token with deploy rights to perform this operation"
} +0ms
  sanity:client [2] ERROR: Unauthorized - User must be an administrator or a token with deploy rights to perform this operation +1ms
✖ 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)
(base) Josephs-MBP-2:cms jiovino$ 
There are. I’m guessing it’s due to your @sanity/client version. Any chance you’d be willing to update?
sanity:client [2] ERROR: Unauthorized - User must be an administrator or a token with deploy rights to perform this operation +1ms
Aha. I think this may be it. I only have Read + Write access – gotta get Admin permission. I will update and try again as well.
Oh. For sure that’s it. I should have kept scrolling!
Thank you so much!!!!

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?