错误响应节点js api

时间:2017-08-24 10:40:20

标签: javascript node.js ajax api

我正在创建一个节点JS API(ES6),该应用程序正在使用google firebase for auth db等。 我正在尝试向客户发回一个回复我们有一个错误就像一个无效的密码我搜索了一下我尝试了一些人说的但没有成功。

编辑:

我已经编辑了路线,所以就像那样 现在得到错误响应但不是我发送的响应文本

在路径文件中我有:

app.route('/signin')
.post(auth.SignIn , function(req ,res) {
});
我在控制器上的

    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 - ");
}

在客户端:

  $("#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);
      }
    });

  });

当登录不正确时,我从此行获取node.js控制台上的错误:

console.log(errorCode + " - " + errorMessage);

如果有人知道如何解决这个问题我将非常高兴:) 感谢。

1 个答案:

答案 0 :(得分:-3)

也许你可以尝试解决它:

app.post('/signin',SignIn(req,res))
相关问题