json - Json中未定义的值数组
问题描述
这是我获取登录用户数据的代码
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 之类的数据的客户字段数据,它似乎未定义。那么我如何获取数据而不是未定义,如果您知道,请告诉我未定义值背后的原因
提前感谢您的帮助,让我的一天更美好。
解决方案
推荐阅读
- sapui5 - sapui5 如何为 sap.m.Select Tag 提供占位符
- installation - NetAdvantage_NET_20081_CLR20_Product.exe:安装因错误而提前结束
- python - TicTacToe - 如果有赢家,我如何停止游戏,
- c++ - `x = &v` 和 `*x = v` 是等价的吗?
- node.js - 在高端机器上创建反应应用程序生产构建速度非常慢
- reactjs - 某些视图正在加载,而其他视图则不会在后退按钮上按下 ReactJS
- r - data.table::fread 无法使用 cmd 参数读取数据
- c++ - 在非常量上下文中使用 std::size
- java - 使用 Java 将多个图像转换为灰度
- python-3.x - 高效的二维列表初始化 [python]