Created
February 3, 2022 10:45
-
-
Save SimeonGriggs/43bb34966bf76b9623af544008fa0285 to your computer and use it in GitHub Desktop.
A tool that renders differently based on User Role Name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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