Answer the question
In order to leave comments, you need to log in
How to set up separation of roles (user, moder, admin) inside a React project?
Let's say there is a ready project on React. How to set up separation of roles (user, moder, admin) inside a React project?
Answer the question
In order to leave comments, you need to log in
For starters, the role check must be implemented on the back so that the user cannot bypass the ui perform actions that are not intended for him or receive data that is closed to him.
Further, the simplest option is a restriction at the routing level, everything is clear here in general, when permissions are checked before going to a separate page, otherwise we show a stub that access to this section is limited.
If it is required to separate one page at the ui level, when we have a button for editing data, for example, but a normal user can only watch, and the button should be active for the editor / admin, then this will already have to be done at the component level and a separate check of certain rules for specific role.
For example, I solved such a problem in the following way:
1. Created an object of access rules for various components/pages.
const rules = {
articles: {
create: 'articles:create',
edit: 'articles:edit'
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question