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

118
Views
Router does not respond to changes in state. Vue

Router: check auth before render

router.beforeEach((to, from, next) => {
  const requireAuth = to.meta.auth

  if (requireAuth && store.getters['auth/isAuthenticated']) {
    next()
  } else if (requireAuth && !store.getters['auth/isAuthenticated']) {
    next({name: 'login'})
  } else if (!requireAuth && store.getters['auth/isAuthenticated']) {
    next({name: 'admin'})
  } else {
    next()
  }
})

Vuex:

state() {
    return {
      isAuth: false,
      user: null,
      emailFormFactor: ''
    }
  },
 getters: {
    isAuthenticated(state) {
      return state.isAuth
    },
    getEmailFormFactor(state) {
      return state.emailFormFactor
    },
    getUser(state) {
      return state.user
    }
  }

App

onBeforeMount(
      () => {
        if (localStorage.getItem('auth-token')) {
          store.dispatch('auth/checkAuth')
        }
      }
    )

Before,i hve to check the validity of the token and after that, if there is a change of state. Does it need to be tracked in the router? Thanks

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!