I just find one bug in serializeUser
, put user.id
in callback not done
try and don't use return
in serializeUser
and deserializeUser
like this:
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
and remove this line in Passport file, because don't need to exports
module.exports=passport;
and use bodyParser module to parse body of requests to json
const bodyParser = require('body-parser');
app.use(bodyParser.json())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…