I have a authentication system using passport, I dont know why but the it returns 'undefined' value, can somebody help me, Here's my code below:
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
});
This also happens when I render a page that has a req.profile variable.
Use req.user rather than req.profile