Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement