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

122
Vistas
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 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