Skip to content

Instantly share code, notes, and snippets.

@iswanj
Last active January 14, 2016 08:19
Show Gist options
  • Save iswanj/029c2a09bd4431a8bc54 to your computer and use it in GitHub Desktop.
Save iswanj/029c2a09bd4431a8bc54 to your computer and use it in GitHub Desktop.
Handling Permissions
const isPremited = (roles, type) => {
// premission check logic
return ...;
}
export { isPremited };
import React from 'react';
import { isPremited } from './premission'; // custom module
class UserList extends React.Component {
renderEdit() {
let { roles } = this.props;
if(!isPremited(roles, 'EDIT_USER')) return null;
return (
<Button>Edit</Button>
);
}
render() {
let editButton = () => { this.renderEdit(); }
return(
<div>
<User />
{editButton}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment