Skip to content

Instantly share code, notes, and snippets.

@acacha
Created April 16, 2018 15:56
Show Gist options
  • Save acacha/664967aa662162c30da7acedc9f232be to your computer and use it in GitHub Desktop.
Save acacha/664967aa662162c30da7acedc9f232be to your computer and use it in GitHub Desktop.
import * as mutations from '../../mutation-types'
import * as actions from '../../action-types'
import auth from '../../../api/auth'
export default {
[ actions.LOGIN ] (context, credentials) {
return new Promise((resolve, reject) => {
auth.login(credentials).then(response => {
context.commit(mutations.LOGGED, true)
resolve(response)
}).catch(error => {
reject(error)
})
})
},
[ actions.LOGOUT ] (context) {
return new Promise((resolve, reject) => {
auth.logout().then(response => {
context.commit(mutations.LOGGED, false)
resolve(response)
}).catch(error => {
reject(error)
})
})
},
[ actions.REGISTER ] (context, user) {
return new Promise((resolve, reject) => {
auth.register(user).then(response => {
context.commit(mutations.LOGGED, false)
resolve(response)
}).catch(error => {
reject(error)
})
})
},
[ actions.REMEMBER_PASSWORD ] (context, email) {
return new Promise((resolve, reject) => {
auth.remember(email).then(response => {
resolve(response)
}).catch(error => {
reject(error)
})
})
},
[ actions.RESET_PASSWORD ] (context, user) {
return new Promise((resolve, reject) => {
auth.reset(user).then(response => {
resolve(response)
}).catch(error => {
reject(error)
})
})
}
}
export default {
logged: state => state.logged,
token: state => state.token,
user: state => state.user,
roles: state => state.user ? state.user.roles : []
}
import getters from './getters'
import actions from './actions'
import mutations from './mutations'
const state = {
token: null,
user: null,
logged: false
}
export default {
state,
getters,
actions,
mutations
}
import * as types from '../../mutation-types'
export default {
[ types.LOGGED ] (state, logged) {
state.logged = logged
},
[ types.USER ] (state, user) {
state.user = user
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment