Skip to content

Instantly share code, notes, and snippets.

@jdltechworks
Created June 20, 2018 02:53
Show Gist options
  • Save jdltechworks/df3ab8e71a8bac0c0bc20c7c275d1bf4 to your computer and use it in GitHub Desktop.
Save jdltechworks/df3ab8e71a8bac0c0bc20c7c275d1bf4 to your computer and use it in GitHub Desktop.
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