Skip to content

Instantly share code, notes, and snippets.

@jbaxleyiii
Created January 24, 2017 20:44
Show Gist options
  • Save jbaxleyiii/5b14ecb186350a7dcaf8cfc830db7620 to your computer and use it in GitHub Desktop.
Save jbaxleyiii/5b14ecb186350a7dcaf8cfc830db7620 to your computer and use it in GitHub Desktop.
// 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