Created
June 20, 2018 02:53
-
-
Save jdltechworks/df3ab8e71a8bac0c0bc20c7c275d1bf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios' | |
import authTypes from './mutation-types' | |
import loadingTypes from '~/store/modules/loader/types' | |
const types = authTypes(true) | |
const loading = loadingTypes() | |
export default { | |
Logout({ commit }) { | |
commit(types.LOGOUT) | |
setTimeout(() => commit(loading.END), 300) | |
}, | |
async Login({ commit, state }) { | |
const { | |
username, | |
password, | |
client_id, | |
client_secret, | |
grant_type | |
} = state | |
commit(loading.START, null, { root: true }) | |
try { | |
const { data } = await axios.post('/api/login', { | |
username, | |
password, | |
client_id, | |
client_secret, | |
grant_type | |
}) | |
commit(types.SUCCESS, { ...data }) | |
const response = await axios.get('/api/user') | |
commit(types.USER, { ...response.data }) | |
} catch(errors) { | |
commit(types.FAILED, { errors }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment