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

138
Views
I get an infinite loop when i try to navigata to login page

here is the router.beforeEach function, when the client is not authenticated then he navigate to login page.

router.beforeEach(async (to, from, next) => {
  if ( to.name !== 'signup' || to.name !== 'login' ) {
    if (await checkAuth()) {
     next()
    } else {
      next({name: 'login'})
    } 
  } else {
    next()
  } 
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's because of how you write your condition.

if you're going to login page while unauthenticated the flow goes like:

  • 'login' !== 'signup' (true)
  • await checkAuth() (false)
  • execute next({ name: 'login' })

Maybe you meant:

const pagesForAuthOnly = []
const pagesForGuestsOnly = ['login', 'signup']
const authenticated = await checkAuth()

if (pagesForAuthOnly.includes(to.name)) {
  if (authenticated) {
    next()
  } else {
    next({ name: 'login' })
  }
} else if (pagesForGuestsOnly.includes(to.name)) {
  if (authenticated) {
    next({ name: 'home' })
  } else {
    next()
  }
} else {
  next()
}

about 4 years ago · Juan Pablo Isaza Report
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!