如果用户身份验证无法正常工作

If User Authentication Cannot Work Propoerly

我想使用 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

但我不明白为什么它不起作用。谁能帮我解决这个问题:

不要在 pug 中使用默认的 if 表达式,而是尝试使用 JavaScript 来评估表达式的真实性。因此,尝试使用 - if(user._id == kullanici._id)

而不是 if user._id == kullanici._id

Pug 标签声明和它的内容之间需要一个 space。

a(href='#')Content //incorrect
a(href='#') Content //correct

在这种情况下,您需要在右括号后(在 Düzenle 之前)添加一个 space,如下所示:

if user
  if user._id == kullanici._id
    a.button.btn.btn-light(href='/kullanici/duzenleme/' + kullanici.id, style="margin-right:85%;") Düzenle

我通过将这个添加到我的哈巴狗模板中解决了这个问题===>

if user
  if user._id == ""+kullanici._id+""
    a.button.btn.btn-light(href='/kullanici/duzenleme/' + kullanici.id, style="margin-right:85%;")Düzenle