0
我使用的护照,我不知道为什么,但它的回报“未定义” 值,可以有人帮助我有一个认证系统,下面是我下面的代码:我的身份验证系统返回undefined
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变量页面也会发生这种情况。
做的第一路径('POST/login')实际登录的东西'req.profile'?如果登录会话处于活动状态,护照将填充'req.user',但不包含'req.profile'。 – robertklep
谢谢你,我懂了,非常感谢你 –