weixin_33694620 2017-08-24 10:40 采纳率: 0%
浏览 16

错误响应节点js API

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.

  • 写回答

1条回答 默认 最新

  • H_MZ 2017-08-24 10:44
    关注

    Maybe you could fix it trying:

    app.post('/signin',SignIn(req,res))
    
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来