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

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