title: How to set property to req.session
body: <p>I am newby in node.js and sessions and I have problem is setting properties to sesssion ! I try to add property to session and save it in db but I get error</p>
  
  <p>here is my codes : 
  app.js : ( main js file )</p>
  
  <pre><code>const store = new MongoDBStore({
      uri : 'mongodb://127.0.0.1:27017/OnLineShop',
      collection : 'session'
  })
  
  // routes :
  app.use(shopRoutes)
  app.use('/admin', adminRoutes)
  app.use(authroutes)
  
  
  // session : 
  app.use(session(
      {
          secret : 'secret key' , 
          resave : false , 
          saveUninitialized : false , 
          store : store
      }
  ))
  </code></pre>
  
  <p>and here is my authentication handler I named it auth.js :</p>
  
  <pre><code> // rout handler for post login requst : 
      module.exports.postLogin = (req , res)=&gt;{
          // session : 
          req.session.isLoggedIn = true 
          res.redirect('/')
      }
  </code></pre>
  
  <p>after I lunch this app and want to login this error appear : </p>
  
  <pre><code>TypeError: Cannot set property 'isLoggedIn' of undefined
      at module.exports.postLogin (/home/sadra/Desktop/projects/web/javascript/shop-app/controllers/auth.js:15:28)
      at Layer.handle [as handle_request] (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/layer.js:95:5)
      at next (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/route.js:137:13)
      at Route.dispatch (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/route.js:112:3)
      at Layer.handle [as handle_request] (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/layer.js:95:5)
      at /home/sadra/Desktop/projects/web/javascript/nodejs_frontCast/shop-app/node_modules/express/lib/router/index.js:281:22
      at Function.process_params (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/index.js:335:12)
      at next (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/index.js:275:10)
      at Function.handle (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/index.js:174:3)
      at router (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/index.js:47:12)
      at Layer.handle [as handle_request] (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/layer.js:95:5)
      at trim_prefix (/home/sadra/Desktop/projects/web/javascript/nodejs_frontCast/shop-app/node_modules/express/lib/router/index.js:317:13)
      at /home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/index.js:284:7
      at Function.process_params (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/index.js:335:12)
      at next (/home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/index.js:275:10)
      at /home/sadra/Desktop/projects/web/javascript/shop-app/node_modules/express/lib/router/index.js:635:15
  </code></pre>
  
  <p>I don`t know how we can set property for session in right way !</p>