1

I currently have a mongoose/express/passportjs application that I can successfully log in and out with. However, only the user ID is stored in the session. I'd like the store the whole user object.

Here is the code I use:

passport.serializeUser(function(user, done) {
  done(null, user._id);
});

passport.deserializeUser(function(_id, done) {
  done(null, { _id: _id });
});

Works great, here is why I tried to serialize the entire user:

passport.serializeUser(function(user, done) {
  done(null, user._id);
});

passport.deserializeUser(function(user, done) {
  done(null, user);
});

However, it doesn't store any session with that.

What am I doing wrong?

4

1 に答える 1

1

ユーザー全体を次serializeUserのように渡す必要があります。done

passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(user, done) {
  done(null, user);
});
于 2014-08-14T00:00:06.293 に答える