Encountering an issue with async method implementation.
In my authServices, there is a loginWithCredential function which is asynchronous:
async loginWithCredential(username, password){
var data = {username: username, password: password};
api.post('/api/users/login', data)
.then(successCallback, errorCallback)
function successCallback(response) {
return response.data;
}
function errorCallback(error){
console.error(error);
return false;
}
}
Within my store, I am attempting to retrieve the data:
@action login (user, password) {
this.isAuthenticating = true;
// Additional code above, focusing on setting token here
return authServices.loginWithCredential(user, password).then(function(response){
console.log(response);
},function(response){
console.log(response);
});
}
The issue lies in the fact that the response in my store is consistently undefined as it is executed before the service has completed its return. Any suggestions on how to address this?