Update modules.
This commit is contained in:
parent
43eece2539
commit
945ea5e69f
3 changed files with 144 additions and 91 deletions
38
src/modules/users.js
Normal file
38
src/modules/users.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import apiService from '../services/api/api.service.js'
|
||||
|
||||
const users = {
|
||||
state: {
|
||||
currentUser: false,
|
||||
loggingIn: false
|
||||
},
|
||||
mutations: {
|
||||
setCurrentUser (state, user) {
|
||||
state.currentUser = user
|
||||
},
|
||||
beginLogin (state) {
|
||||
state.loggingIn = true
|
||||
},
|
||||
endLogin (state) {
|
||||
state.loggingIn = false
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
loginUser ({commit, state}, userCredentials) {
|
||||
commit('beginLogin')
|
||||
apiService.verifyCredentials(userCredentials)
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
response.json()
|
||||
.then((user) => commit('setCurrentUser', user))
|
||||
}
|
||||
commit('endLogin')
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error)
|
||||
commit('endLogin')
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default users
|
Loading…
Add table
Add a link
Reference in a new issue