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

120
Views
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
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!