I am creating a login script that should return the responseData back to the calling class. The problem is that I am constantly getting undefined with the returned result. If I console log the responseData it shows up fine. One thing I have noticed is that the undefined sometimes appears before the console log responseData in the console.
module.exports = {
loginUser: function( emailAddress = "", password = "" ) {
var url= "URL_HERE";
console.log(url);
fetch(url, {method: "GET"})
.then((response) => response.json())
.then((responseData) =>
{
console.log(responseData);
return responseData;
})
.done(() => {
});
},
otherMethod: function() {}
}
Here is an example of how the function is called
var dataLogin = require('../../data/login.js');
var result = dataLogin.loginUser(this.state.formInputEmail, this.state.formInputPassword);