Error ExpressJS: Object # & lt; Object & gt; does not have a 'resetMaxAge' method

advertisements

Here's my ExpressJS controller:

exports.authenticate = function(req, res) {
      Company.findOne({_id: user.company_id}, function(err, company) {
        if(err) {
          response = {
            status: 'error',
            error: err
          }
        } else if(!company) {
          response = {
            status: 'error',
            error: 'User not identified with a company'
          }
        } else {
          req.session = user;
          response = {
            status: 'ok',
            user: user,
            api_key: company.api_key
          }
          return res.json(response);
        }
      });
    }
}

In my express config, I have:

app.use(express.session({
  secret: config.sessionSecret,
  store: new mongoStore({
    db: db.connection.db,
    collection: config.sessionCollection
  })
}));

The error I get is: TypeError: Object #<Object> has no method 'resetMaxAge'


Try changing the express config to:

 app.use(express.session({
      "secret" : config.sessionSecret,
      key: 'PutYourKey',
      cookie: {secure: false, maxAge: 300000},
      store: new mongoStore
      ({
         db: db.connection.db,
         collection: config.sessionCollection
      })
  }));