Passport.js - Error: failed to serialize user into session
Solution 1:
It looks like you didn't implement passport.serializeUser
and passport.deserializeUser
. Try adding this:
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
Solution 2:
If you decide not to use sessions, you could set the session to false
app.post('/login', passport.authenticate('local', {
successRedirect: '/accessed',
failureRedirect: '/access',
session: false
}));
Solution 3:
Sounds like you missed a part of the passportjs setup, specifically these two methods:
passport.serializeUser(function(user, done) {
done(null, user._id);
// if you use Model.id as your idAttribute maybe you'd want
// done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
I added the bit about ._id
vs. .id
but this snippet is from the Configure Section of docs, give that another read and good luck :)