Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Setting field schema settings based on user roles in Sanity.io

3 replies
Last updated: Aug 15, 2024
Hey all,
Would anyone know if it's possible to set up individual field schema settings based on the user's role, for example set a field to hidden or readonly if it's specific role viewing the document? I know there is a useCurrentUser hook, but that can only be used in a React component, not in schema or config files, and I don't have custom components, I'm using the basic field types (e.g. string, image etc). What would be a good solution for this?
Aug 15, 2024, 1:19 PM
The
currentUser
is passed into that
context
in the second argument of hidden/read only callbacks. You can find out a user’s role there!
Aug 15, 2024, 6:12 PM
That works, thanks!
Aug 15, 2024, 9:12 PM
You’re welcome!
Aug 15, 2024, 11:00 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?