Tuesday 30 May 2017

Session issues with Passportjs

I am trying to use passportjs in my nodejs app with express4. For testing purpose, I am using session-file-store to keep session.

The way I set up the session and passportjs :

this.app.use(session({
  secret: process.env.SESSION_SECRET || configuration.session_secret,
  store: new fileStore(),
  resave: false,
  saveUninitialized: false
}));

// config authentication
this.app.use(passport.initialize());
this.app.use(passport.session());
// Configure Passport
passport.use('local-login', new localStrategy.Strategy(
    (username, password, done) => {
      Services.users.authenticatePromise(username, password).then(
          function(token) {
            done(null, token);
          },
          function(err) {
            done(null, false, err);
          },
      ).done();
    },
));

However, the issue I am having is that if I don't write anything into the session before user is logged in, passportjs works fine. However if I am trying to write some data into session like shopping cart details, then passportjs would not be able to serialize the user token into the session store any more. so login cannot be successful.

What am I missing?



via rzhomx

No comments:

Post a Comment