blob: 3f6864a2bd7ff9a457fee83fc16c0a84b9700bcb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import apiService from '../services/api/api.service.js'
import timelineFetcher from '../services/timeline_fetcher/timeline_fetcher.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 (store, userCredentials) {
const commit = store.commit
commit('beginLogin')
return apiService.verifyCredentials(userCredentials)
.then((response) => {
if (response.ok) {
response.json()
.then((user) => commit('setCurrentUser', user))
.then(() => timelineFetcher.startFetching({store, credentials: userCredentials}))
}
commit('endLogin')
})
.catch((error) => {
console.log(error)
commit('endLogin')
})
}
}
}
export default users
|