【发布时间】:2020-06-20 15:26:26
【问题描述】:
我想使用 if user 方法进行身份验证。当我执行 console.log(user) 和 cosole.log(kullanici) 时,我得到了正确的数据。
kullanici 是指个人资料中显示的用户。
user 表示当前登录的用户(req.user)
我的 app.js 文件:
app.get('/kullanici/:id', function(req, res){
Kullanici.findById(req.user
).exec(function(err, user){
Kullanici.findById(req.params.id, function(err, kullanici){
res.render("kullanici",{
kullanici:kullanici,
user:user,
});
});
});
});
我的 kullanici.pug 文件:
if user
if user._id == kullanici._id
a.button.btn.btn-light(href='/kullanici/duzenleme/' + kullanici.id, style="margin-right:85%;")Düzenle
但我不明白为什么它不起作用。有人可以帮我解决这个问题吗:
【问题讨论】:
-
尝试控制台记录
user._id和kullanici._id的值和类型。如果它们是字符串,还要确保没有前导或尾随空格。您还可以记录测试结果console.log(user._id == kullanici._id) -
不,它给出了配置文件用户的 ID 和 req.user 的 ID
-
原来如此