Created
April 16, 2018 15:56
-
-
Save acacha/664967aa662162c30da7acedc9f232be 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 * 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) | |
}) | |
}) | |
} | |
} |
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
export default { | |
logged: state => state.logged, | |
token: state => state.token, | |
user: state => state.user, | |
roles: state => state.user ? state.user.roles : [] | |
} |
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 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 | |
} |
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 * 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