In passportjs serialization and deserialization, how can I access browser cookie (I am storing session data on persistent browser cookie ) instead of storing in database.
If you have configured the passport middleware correctly the passport session data will be passed as parameter to the method passport.deserializeUser.
Be sure that passport has been set up correctly in express:
app.use(express.cookieParser());
app.use(express.session({ secret: 'your secret phrase' }));
app.use(passport.initialize());
app.use(passport.session());
Implement passport.serializeUser and passport.deserializeUser:
// user contains the user data returned by the authentication strategy
passport.serializeUser(function(user, done) {
done(null, user);
});
// obj contains the passport session data
passport.deserializeUser(function(obj, done) {
// Use obj to get user info or include it directly into the request object
done(null, obj);
});
User data will be available in req.user.