We have a requirement where we have to set the privilege for each action, control and pages in our reactjs project. We want to set the privilege in one place of our application. What is the best way to set the privilege in reactjs project?
Asked
Active
Viewed 188 times
0
-
Can you give an example of a privileged action? What are you validating, and what function would execute if it "privileged" is true? – meteorBuzz Jun 23 '17 at 11:23
-
@meteorBuzz privileged action like add, edit and update update. – Gorakh Nath Jun 23 '17 at 12:44
1 Answers
1
Your requirements can be met by using a singleton store, and/or using a controller component. From how you've described it, what you want is to set up some kind of roles & capabilities system that effects the rendered content, e.g. show certain menu options to admins and different ones to unauthenticated users.
Fortunately, there already exists a controller-view pattern in react-router, which you can configure to pass in certain props based on the type of user. This article does a good job in describing how to set that up, using the redux implementation of flux.

Josh from Qaribou
- 6,776
- 2
- 23
- 21