1

パスポートを使用した認証システムがあります。理由はわかりませんが、「未定義」の値が返されます。誰か助けてください。以下のコードは次のとおりです。

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 変数を持つページをレンダリングするときにも発生します。

4

1 に答える 1

0

req.profileではなくreq.userを使用する

于 2014-11-19T06:58:48.660 に答える