import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'; import { StateInterface } from 'src/store'; import { axios } from 'src/boot/axios'; export interface SessionInterface { sessions: FG.Session[]; loading: boolean; } const state: SessionInterface = { sessions: [], loading: false }; const mutations: MutationTree = { setSessions(state, sessions: FG.Session[]) { state.sessions = sessions; }, setLoading(state, value: boolean) { state.loading = value; } }; const actions: ActionTree = { getSessions({ commit, rootGetters }) { console.log(rootGetters); commit('setLoading', true); axios .get('/auth') .then(response => { console.log(response.data); commit('setSessions', response.data); }) .catch(error => { console.exception(error); }) .finally(() => { commit('setLoading', false); }); }, deleteSession({ commit, dispatch }, token: string) { commit('setLoading', true); console.log('axios', axios); axios .delete(`/auth/${token}`) .then(() => { void dispatch('getSessions'); }) .catch(error => { console.exception(error); }) .finally(() => { commit('setLoading', false); }); } }; const getters: GetterTree = { sessions(state) { return state.sessions; }, loading(state) { return state.loading; } }; const sessions: Module = { namespaced: true, state, mutations, actions, getters }; export default sessions;