I'm creating a node JS API (ES6) the app is using google firebase for auth db and more. I'm trying to sent the client a response back we there is an error like an invalid password I search a bit and I tried some things people say and no success.
EDIT:
I have edited the route so it will be like that now getting the error response but not with the response text i sent
in the route file I have:
app.route('/signin')
.post(auth.SignIn , function(req ,res) {
});
on the controller I have:
exports.SignIn = function(req, res) {
var email = req.body.email;
var password = req.body.password;
console.log(req.body.email + " - Attempting To SignIn");
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode + " - " + errorMessage);
res.send(error.message);
});
console.log(email + " - Is Signed In - ");
}
on the client:
$("#signinform").submit(function(event) {
alert("test");
/* stop form from submitting normally */
event.preventDefault();
var formData = {
'email': $('input[name=ident]').val(),
'password': $('input[type=password]').val()
};
$.ajax({
type: 'POST',
url: "http://localhost:3000/signin",
data: formData,
success: function(res){
alert(res);
},
error: function(res){
alert(res);
}
});
});
when the log in is incorrect I get the error on the node.js console from this line:
console.log(errorCode + " - " + errorMessage);
if any one knows how to fix this I will be very happy :) Thanks.