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

124
Visualizações
alert is being called 2 times for 1 call in React

I have this code that checks if the user is logged in or not by getting the cookie. So if the cookie is not found then it alerts and navigates the user to the login page.

// trying to get the token
  const tokenExists = Cookies.get('auth-token')
  
  // if no cookie found then redirect the user to the login route to get their auth-token
  if (!tokenExists) {
    alert('Please log in to continue')
    return <Navigate to='/login' />
  }

but when this code gets executed, it alerts two times saying "Please log in to continue" and then redirects the user to the login page when there is only 1 alert call. I'm not sure what is wrong.

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