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

255
Vistas
Using Vuex Action inside Axios global configuration

Assuming we have the following Vuex store action:

  authAction({ commit }) {
    firebase.auth().onAuthStateChanged((user) => {
      if (user) {
        commit("setUser", user);
      } else {
        commit("setUser", null);
      }
    });
  }

And the setUser mutation is as follows:

  setUser(state, payload) {
    state.user = payload;
  }

Alongside the following getter:

  getUser(state) {
    return state.user;
  }

And my configuration file with Gridsome is as follows:

  Vue.use(Vuex);
  appOptions.store = new Vuex.Store(store);

  axios.defaults.baseURL = process.env.GRIDSOME_API_URL;
  axios.interceptors.request.use(async (config) => {
    
    try {
      await appOptions.store.dispatch('authAction');
      const user = // some code to get the object returned from getUser
      let token = await user.getIdToken(true);
      config.headers.Authorization = `Bearer ${token}`;
      return config;
    } catch (err) {
      return Promise.reject(err);
    }
  });

So, basically I want to get my object after having dispatched the action authAction. How can I access this object?

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