Created
January 24, 2017 20:44
-
-
Save jbaxleyiii/5b14ecb186350a7dcaf8cfc830db7620 to your computer and use it in GitHub Desktop.
This file contains 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
// canSee.js | |
gql` | |
query GetSecurityRoles { | |
roles: securityRoles { | |
key | |
} | |
} | |
`; | |
// { | |
// loading: boolean, | |
// roles: [{ | |
// key: "Staff" | |
// }], | |
// } | |
const canSee = (roles) => graphql(QUERY, { | |
props: ({ data }) => ({ | |
...data, | |
authorized: ( | |
!data.loading && | |
includes(data.roles, roles); | |
) | |
}) | |
}); | |
export const isStaff = canSee(["Staff"]); | |
export default canSee; | |
// usage | |
import { isStaff } from "../canSee"; | |
const SecretCode = ({ loading, authorized }) => { | |
// XXX can one line this | |
if (loading) return null; | |
if (!authorzied) return null; | |
return ( | |
<h1>James doesn't know javascript</h1> | |
); | |
}; | |
export default isStaff(SecretCode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment