Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda