Skip to content

Instantly share code, notes, and snippets.

@SimeonGriggs
Created February 3, 2022 10:45
Show Gist options
  • Select an option

  • Save SimeonGriggs/43bb34966bf76b9623af544008fa0285 to your computer and use it in GitHub Desktop.

Select an option

Save SimeonGriggs/43bb34966bf76b9623af544008fa0285 to your computer and use it in GitHub Desktop.
A tool that renders differently based on User Role Name
import React from 'react'
import {Box, Card, Container, Text} from '@sanity/ui'
import {useCurrentUser} from './useCurrentUser'
export default function SuperSecretTool() {
const {roles} = useCurrentUser()
const isAdmin = roles?.length ? roles.find((role) => role?.name === 'administrator') : false
if (!isAdmin) {
return (
<Box padding={5}>
<Container>
<Card tone="critical" padding={5} radius={3} shadow={1}>
<Text>Permission Denied</Text>
</Card>
</Container>
</Box>
)
}
return (
<Box padding={5}>
<Container>
<Card tone="positive" padding={5} radius={3} shadow={1}>
<Text>Only Admins should see this!</Text>
</Card>
</Container>
</Box>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment