Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda