Json内部的未定义值数组

时间:2018-08-18 05:14:12

标签: json node.js

这是我获取登录用户数据的代码

router.post('/login', function (req, res, next) {
  /* look at the 2nd parameter to the below call */
  let errors = [];
  if (!req.body.password || !req.body.email) {
    req.flash('error_msg', 'please enter email and password');
    res.redirect('/login')
  }
  passport.authenticate('local', function (err, user, info) {
    if (err) { return next(err); }
    if (!user) {
      req.flash('error_msg', 'your email or password is not correct');
      res.redirect('/login')
    }
    req.logIn(user, function (err) {
      if (err) { return next(err); }
      var type = user.type;
      var dt = dateTime.create();
      var formatted = dt.format('Y-m-d H:M:S');
      connection.query("update table set last_login = '"+formatted+"' where id = '"+user.id+"'", function (err, rows) {
        if(type == '0'){
          res.redirect('/login');
        }
        else if(type == '1'){
          console.log(user);
          res.cookie('user', user).redirect('/dashboard');
        }
        else{
          res.redirect('/customers');
        }
      });
    });
  })(req, res, next);
});

我试图在节点js中管理一些数据,并且其中的数据正在获得类似的结果。

{ 
  email: 'test@gmail.com',
  username: 'tester',
  id: 9,
  password: '7ZaOhA0Q0tMTqHC8ExpOLDEdetCb3zKzQYFHIh9RpuI=',
  type: '1',
  token: 
 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImVtYWlsIjoic2l2YWFAZ21haWwuY29tIiwidXNlcm5hbWUiOiJzaXZhYSIsImlkIjo5LCJwYXNzd29yZCI6IjdaYU9oQTBRMHRNVHFIQzhFeHBPTERFZGV0Q2Izekt6UVlGSEloOVJwdUk9IiwidHlwZSI6IjEiLCJ0b2tlbiI6IiJ9LCJpYXQiOjE1MzQ1Njg3NjEsImV4cCI6MTUzNDU3MTc2MX0._3AspvfLO2K46OVilqsLtfiRcZTG2ZYvGJWe6jaQ3ZA',
  customers: undefined 
}

现在,我想显示客户字段数据,其中包含诸如abc,xyz,pqr之类的数据,并且似乎未定义。 所以我如何获取数据而不是未定义的数据,如果知道的话,请告诉我未定义的值的原因

预先感谢您的帮助,让我的日子更加美好。

0 个答案:

没有答案