|
|
|
@ -67,6 +67,7 @@ const users = {
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
loginUser (store, userCredentials) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const commit = store.commit
|
|
|
|
|
commit('beginLogin')
|
|
|
|
|
store.rootState.api.backendInteractor.verifyCredentials(userCredentials)
|
|
|
|
@ -94,12 +95,23 @@ const users = {
|
|
|
|
|
store.rootState.api.backendInteractor.fetchFriends()
|
|
|
|
|
.then((friends) => commit('addNewUsers', friends))
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// Authentication failed
|
|
|
|
|
commit('endLogin')
|
|
|
|
|
if (response.status === 401) {
|
|
|
|
|
reject('Wrong username or password')
|
|
|
|
|
} else {
|
|
|
|
|
reject('An error occurred, please try again')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
commit('endLogin')
|
|
|
|
|
resolve()
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
commit('endLogin')
|
|
|
|
|
reject('Failed to connect to server, try again')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|