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

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