Studio excellence
Markdown Version
Member-specific options
Log in to watch a video walkthrough of this lesson
Log in

The Studio’s configuration can respond to the current member’s role, offering a more guided experience for content creation.
Log in to mark your progress for each Lesson and Task
Review Roles in the documentation
If members of a specific role should not be able to edit a field, but will benefit from seeing its current value, mark it as read-only by inspecting the current user's roles.
Update the
event
document type's slug field so only administrators can modify an existing slugdefineField({ name: 'slug', type: 'slug', group: 'details', options: {source: 'name'}, validation: (rule) => rule.required().error(`Required to generate a page on the website`), hidden: ({document}) => !document?.name, readOnly: ({value, currentUser}) => { // Anyone can set the initial slug if (!value) { return false }
const isAdmin = currentUser?.roles.some((role) => role.name === 'administrator')
// Only admins can change the slug return !isAdmin },}),
This will only protect the field in the Studio and not from an API request
The same function is available in the hidden
key, so fields are not visible to specific users.
Note that the field's value will still appear in the data, and an invalid field can still be hidden – potentially leading to confusion.
Review Studio Tools and Studio tools reference in the documentation
Tools can be conditionally loaded depending on – among other variables – the current user.
Perhaps you only want Administrators to see the Vision plugin for testing GROQ queries. The code below will return a filtered list to all non-administrator role users.
Update
sanity.config.ts
so that only administrators can see the Vision toolexport default defineConfig({ // ...all other settings tools: (prev, {currentUser}) => { const isAdmin = currentUser?.roles.some((role) => role.name === 'administrator')
if (isAdmin) { return prev }
return prev.filter((tool) => tool.name !== 'vision') },})
You have 2 uncompleted tasks in this lesson
0 of 2