Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // canSee.js
  2.  
  3. gql`
  4. query GetSecurityRoles {
  5. roles: securityRoles {
  6. key
  7. }
  8. }
  9. `;
  10.  
  11. // {
  12. // loading: boolean,
  13. // roles: [{
  14. // key: "Staff"
  15. // }],
  16. // }
  17. const canSee = (roles) => graphql(QUERY, {
  18. props: ({ data }) => ({
  19. ...data,
  20. authorized: (
  21. !data.loading &&
  22. includes(data.roles, roles);
  23. )
  24. })
  25. });
  26.  
  27. export const isStaff = canSee(["Staff"]);
  28. export default canSee;
  29.  
  30.  
  31. // usage
  32. import { isStaff } from "../canSee";
  33.  
  34.  
  35. const SecretCode = ({ loading, authorized }) => {
  36.  
  37. // XXX can one line this
  38. if (loading) return null;
  39. if (!authorzied) return null;
  40.  
  41. return (
  42. <h1>James doesn't know javascript</h1>
  43. );
  44.  
  45. };
  46.  
  47. export default isStaff(SecretCode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement