👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

How to hide structure elements based on user role in Sanity v3.

3 replies
Last updated: Oct 14, 2023
Is there any way to hide structure elements depending on the user role?
For example I want to only show a certain list if the user is an administrator.

It seems this was possible in v2 (
https://www.sanity.io/schemas/desk-structure-with-custom-roles-332e8ada ) but I can't seem to figure out a way to do this in v3. Does anyone know if it's possible? Surely it should be right?
Oct 6, 2023, 12:18 PM
Turns out this IS possible to do, but absolutely nowhere in the documentation. Just in blog posts for v2.
To do this, you can pull the current user off the context object that is exposed alongside the structure builder. This will let you check the roles of users before returning a list.

This really should be in the documentation as this has been giving me a headache for about 2 hours
Oct 6, 2023, 12:32 PM
There’s an example here but you’d pretty much already have to know where it is to find it.
Oct 6, 2023, 4:27 PM
Coming back to this! How would you render certain plugins based on a role (such as media and vision plugin)?
Oct 14, 2023, 10:11 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?