Sanity SSO broken after media plugin install: 401 Unauthorized ACL error
This looks like a bug that was already reported and fixed back in June 2021. Based on the discussion thread I found, here's what happened and how it was resolved:
The issue you're experiencing was caused by an incompatibility between Sanity's SSO implementation and how the Studio was handling user roles. When using SSO with third-party login tokens, the currentUser object has a role property (as a string, like "editor"), but the Studio code was expecting a roles property (as an array).
This caused the error "undefined is not an object (evaluating 'currentUser.roles.length')" in the PermissionCheckBanner component when trying to access currentUser.roles.length.
The good news: This was fixed by the Sanity team within about a day of being reported. There were actually two bugs:
- The
rolesvsroleproperty mismatch (causing the "currentUser.roles.length" error) - A 500 error on the
/aclendpoint due to system groups having an unexpected shape
Both were patched and released.
What you should do:
Update your Sanity packages - Run
npm updateoryarn upgradeto ensure you have the latest versions, particularly@sanity/desk-tool(or@sanity/structurein Studio v3+)Clear your node_modules and reinstall - Sometimes a clean install helps:
rm -rf node_modules package-lock.json npm installCheck your Studio version - If you're still on Studio v2, consider upgrading to Studio v3 (now v4 is available), as these older bugs are definitely resolved in newer versions. Run
sanity upgradeto get the latest versions.Verify your SSO token generation - Make sure your SSO implementation is following the current third-party login documentation and that your tokens are being generated correctly.
If you're still experiencing this issue after updating, it might be a different problem with similar symptoms. The fact that it appeared right after installing the media plugin is likely coincidental - the plugin installation probably just triggered a Studio refresh that exposed an underlying version mismatch.
If problems persist after updating, I'd recommend reaching out to Sanity's community on Discord with your current Studio version and package.json dependencies so the team can help troubleshoot further.
Show original thread14 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.