Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
ReactJS: Handle Role for User

I have a page that I use to check the user authorization

const Routes = auth => {
  return (
    <div className="view-routes">
//...
    <PrivateRoute
          path="/"
          component={Entities}
          hasAnyAuthorities={[AUTHORITIES.USER, AUTHORITIES.ADMIN]}
        />
    // so in this case, the hasAnyAuthorities check if the user has one of this role and return true so I will see the component Entities for this user.
)}

Now I need to add another user's role. So I have add :

const Routes = auth => {
  return (
    <div className="view-routes">
//...
 <PrivateRoute
          path="/"
          component={Menu2}
          hasAnyAuthorities={[AUTHORITIES.USER_APP]}
        />
    <PrivateRoute
          path="/"
          component={Entities}
          hasAnyAuthorities={[AUTHORITIES.USER, AUTHORITIES.ADMIN]}
        />
)}

In this way only the first component (menu2) is always shown. So if I enter with role "USER_APP" I can see the fields in component Menu2. But if I login with role: "ADMIN" I can't see fields inside Entities, as if only the first of the two PrivateRoute were controlled.

What would to obtain:

If I enter with role: USER_APP I'll see the fields in component Menu2.

If I ente with role ADMIN I'll see the fields in the component Entities.

How can I do?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!