Node.js Passport用户把手模板
上面是我用来在res.locals.user字段中设置用户值的代码 控制台给了我: { _id:5fc3e49c0bfce754c8f923c9, 电邮:'myemailadres@hotmail.com', 姓名:“Jarne”, 密码:“passwordhash……”, __v:0 } 在我的句柄栏中,我现在尝试使用这个用户变量Node.js Passport用户把手模板,node.js,express,handlebars.js,passport.js,Node.js,Express,Handlebars.js,Passport.js,上面是我用来在res.locals.user字段中设置用户值的代码 控制台给了我: { _id:5fc3e49c0bfce754c8f923c9, 电邮:'myemailadres@hotmail.com', 姓名:“Jarne”, 密码:“passwordhash……”, __v:0 } 在我的句柄栏中,我现在尝试使用这个用户变量 app.use(passport.initialize()); app.use(passport.session()); app.use(function(req,
app.use(passport.initialize());
app.use(passport.session());
app.use(function(req, res, next) {
res.locals.login = req.isAuthenticated();
res.locals.user = req.user;
console.log(res.locals.user);
next();
});
app.use('/', indexRouter);
这不管用。这是空的。。
我可以使用{{user}},但这会返回Json格式。
我如何访问诸如姓名、电子邮件等字段,。。。在EJS中看到了一些使用user.name、user.\u id的示例,但这在我的车把中似乎不起作用
还试图通过路由器来实现这一点。但tester的结果相同(tester.name不显示任何内容)
我还尝试设置res.locals.username=req.user.name
但这导致了一个错误。我找到了以下解决方案:
router.get('/', function (req, res, next) {
res.render('index', {
title: '---- Dashboard---- HOME',
tester: req.user
});
});
看起来我需要遍历用户对象。我找到了以下解决方案:
router.get('/', function (req, res, next) {
res.render('index', {
title: '---- Dashboard---- HOME',
tester: req.user
});
});
看起来我需要遍历用户对象
{{#each user}}
{{name}}
{{_id}}
{{email}}
{{/each}}