Answer the question
In order to leave comments, you need to log in
How to correctly implement separation of rights in react spa?
Let's say there is a spa application on react. The user logs in using jwt.
It is necessary, depending on the category of the user (individual / legal entity, for example), to display components differently, to allow or prohibit certain routes.
For example, one category can view one section, the other another, or in some component one category has one view, and another category has a different view and set of elements.
Who knows how to do or where to dig?
Answer the question
In order to leave comments, you need to log in
<FORM NAME="form" onSubmit="return Complete();">
<BUTTON TYPE="submit">Готово</BUTTON>
Using react-router routing, for example. In the 4th version I think the same, but we are talking about the 3rd.
Part of the routes wraps in the parent route, which checks the user's rights, and then, depending on this, you draw:
a) different templates in which this.props.children appears
b) null - if access is denied, or again this.props .children - if everything is ok.
In "children" - you will have nested routes.
Verification of rights, I hope, is not included in the question? But if it is: then you need to make a request to the server with this token and get a list of allowed rights.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question