// File: store/modules/auth.js import authProvider from '../../providers/authenticate' import http from '../../providers/http' // You can use it as state property const state = { isAuthenticated: false, user: null }; const getters = { isAuthenticated () { return authProvider.isAuthenticated() }, user () { return state.user } }; const mutations = { isAuthenticated (state, payload) { state.isAuthenticated = payload.isAuthenticated }, user (state, payload) { state.user = payload; } }; const actions = { // Perform VueAuthenticate login using Vuex actions login (context, payload) { return new Promise((resolve, reject) => { authProvider.login(payload.credentials).then((response) => { context.commit('isAuthenticated', { isAuthenticated: authProvider.isAuthenticated() }); http.get('/auth/user') .then(function (response) { context.commit('user', response.data); resolve(); }); }) .catch((err) => { reject(err); }); }); } }; export default { state, getters, actions, mutations }