我的认证系统返回未定义

My authentication system is returning undefined

本文关键字:未定义 返回 系统 认证 我的      更新时间:2023-09-26

我有一个使用护照的身份验证系统,我不知道为什么,但它返回'未定义'有谁能帮我一下,下面是我的代码:

app.js

passport.use(new LocalStrategy(function (username, password, done) {
  Person.findOne({ 'account.username' : username }, function (err, person) {
   if (err) {
     return done(err);
   }
   if (!profile) {
     return done(null, false, { message: 'Invalid username or password' });
   }
   // My self defined function that encrypts the password
   var encryptedPassword = myFunc.encrypt(password);
   if (person.account.password !== encryptedPassword) {
     return done(null, false, { message: 'Invalid username or password' });
   } else {
     return done(null, profile);
   }
  });
}));

person.js

//POST: /login
app.post('/login', passport.authenticate('local', {failureRedirect: '/login',
  failureFlash: true}), 
    function (req, res) {
      console.log(req.profile);
      res.redirect('/home');
    }
  );
//GET: /home
app.get('/home', function (req, res) {
  console.log(req.profile);  // Returns Undefined
});

当我渲染一个有请求的页面时也会发生这种情况。配置变量。

使用请求。用户而不是 req.profile