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?