Skip to content

Instantly share code, notes, and snippets.

@mornir
Created September 19, 2020 18:12
Show Gist options
  • Save mornir/b5096d42a999bbae0ff2d8a360f53395 to your computer and use it in GitHub Desktop.
Save mornir/b5096d42a999bbae0ff2d8a360f53395 to your computer and use it in GitHub Desktop.
Simple example on how to return a structure depending on the logged in user‘s role.
import S from '@sanity/base/structure-builder'
import userStore from 'part:@sanity/base/user'
// remember to add rxjs/operators to your dependencies with npm or yarn
import {
map
} from 'rxjs/operators'
export default () => userStore.currentUser.pipe(
map(({user}) => {
const {role} = user
if (role === 'administrator') {
return S.list().title('Admin structure')
// add more structure
}
return S.list().title('Editor structure')
// add more structure
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment