【发布时间】:2019-09-28 19:46:58
【问题描述】:
我的 app.js 看起来类似于
initialize passport etc
///////////////////////////////////////////
//middleware to pass authuser to req locals
app.use(function (req, res, next) {
res.locals.authUser = req.user;
next();
});
路由器.js
router.get('/',function(req,res){
console.log(res.locals.authUser);
res.render('index');
});
index.ejs 视图
<%= authUser.first_name %>
在 ejs 中,first_name 没有被解析,但如果我放置这个 <%= authUser %> 它会呈现
{
is_admin: true,
_id: 5d8cb3702e35aa2f5cbaabf8,
first_name: 'ruban',
last_name: 'shah',
username: 'admin',
email: 'admin@example.com',
password: 'xxxxxx'
}
这意味着 authUser 是 Object 但它不打印 authUser.first_name is ejs
但奇怪的是它呈现 authUser.username
【问题讨论】:
-
任何属性是否有效?