node.js - nodejs express session not passing variables -


i have problem of session variables not being passed around. believe not store in mongodb since db.sessions.find() empty. modules are

  "express": "~4.12.2","express-session": "~1.11.1","mongoose": "*",     "passport": "~0.2.1", "passport-local": "~1.0.0",   "passport-local-mongoose": "~1.0.0" 

my app.js has

 app.use(cookiesession({   keys: "myapp.sid",   secret: env.get("session_secret"),   saveuninitialized: true,   resave: true,     cookie: { secure: true },   store: new mongostore({ mongooseconnection: mongoose.connection,     touchafter: 24 * 3600                        })  }));  function ensuresecure(req, res, next){  if(req.secure){    return next();  };  res.redirect('https://'+req.hostname+':' + 8000 + req.url); };  app.all('*', ensuresecure);  app.use(csrf({ cookie: true }));  app.use(function(req, res, next) {  res.locals.csrftoken = req.csrftoken();    res.locals.session = req.session;  // flash doesnot passed, maybe same problem  res.locals.sessionflash = req.session.sessionflash;  delete req.session.sessionflash;                                       next(); }); 

it comes before routes. in login route have:

router.post('/login', function (req, res, next) { passport.authenticate('local', function(err, user, info) { if (err) {  return next(err);} if (!user) { ..do something}  var theschema = mongoose.model('oneschema');      theschema.findone({'oneschema': req.body.dbschema}, function(err, oneschemas) {  // go , fetch data,    req.session.role = user.role;  req.session.name = user.username;       console.log("session : %j",req.session);  // ok full info      return res.redirect('/settings');  });  // findone   })(req, res, next);   // end passport line  });  //end login route 

now settings has:

router.get('/settings', function(req, res) {  console.log("session : %j",req.session);  // boum!!!!!  res.render('settings'); }); 

boum!!: session : {"passport":{}}

i have been searching since yesterday, reading around. have tried ideas. cannot make work. appreciate pointers directions can me find solution. thanks


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

android - MPAndroidChart - How to add Annotations or images to the chart -