Skip to content

Instantly share code, notes, and snippets.

@callmephilip
Created March 28, 2020 10:56
Show Gist options
  • Save callmephilip/32941ceb2fd967a4ac25e1dac69e8241 to your computer and use it in GitHub Desktop.
Save callmephilip/32941ceb2fd967a4ac25e1dac69e8241 to your computer and use it in GitHub Desktop.
function deserializeUserPassport(id, done) {
User.findOne({ _id: id }, (err, userModel) => {
if (err) {
done(err);
} else {
if (!userModel) {
done();
return;
}
done(null, userModel.toJSON());
}
});
}
// let's use User id
passport.serializeUser((user, done) => done(null, user._id));
passport.deserializeUser(deserializeUserPassport);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment