1

I have a an object as bellow for user ACl(Access Control list):

{
  'api/modelA': ['GET', 'POST'],
  'api/modelB': ['GET'],
  /*...*/
  'api/modelZ' : ['GET']
}

So after user is authenticated I get the ACLs from server. How can I find a solution for rendering all the components based on these ACls. for instance if user doesn't have access to edit a post the EditButtom component should not be rendered.

Note: for some cases a component will have a different style like gray color if there is no access for the user.

1 Answer 1

1

You can use a higher order component on the component(say EditButton).

function HOC(Component) {
   if(ACL(model).indexOf("POST)
   return   <Component style={{display: none}} />;

   return <Component {...this.props}>;
 }

 render(){
   const HocButton = HOC(EditButton); // EditButton  is some button 

   return (<EditButton>Edit</EditButton>;
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.