title: TypeError: Cannot read property 'csrfSecret' of undefined at Object.handle - using Node.js
body: <p>I am making a simple web app, and trying to add authentication. Everything was working fine (separately) until I tried to merge the authentication pages with the app, and received this error message: </p>
  
  <blockquote>
    <p>"TypeError: Cannot read property 'csrfSecret' of undefined at
    Object.handle(C:Project\node_modules\express\node_modules\connect\node_modules\csurf\index.js:46:29)..."</p>
  </blockquote>
  
  <p>Here is the code in the app.js, perhaps one of you will see where the root of the problem is.</p>
  
  <pre><code>var flash    = require('connect-flash');
  var express  = require('express');
  var app      = express();
  app.use(function(req, res, next) {
    req.db = {};
    req.db.tasks = db.collection('tasks');
    next();
  })
  app.locals.appname = 'Name of App'
  var port     = process.env.PORT || 8080;
  var mongoose = require('mongoose');
  
  var passport = require('passport');
  
  var routes = require('./routes');
  var tasks = require('./routes/tasks');
  var http = require('http');
  var path = require('path');
  var mongoskin = require('mongoskin');
  var db = mongoskin.db('connection works perfectly to my mongolab account', {safe:true});
  
  var configDB = require('./config/database.js');
  
  
  mongoose.connect(configDB.url); 
  
  require('./config/passport')(passport); 
  
  app.configure(function() {
  
  
      app.use(express.logger('dev')); 
      app.use(express.cookieParser());
      app.use(express.bodyParser()); 
  
      app.set('views', __dirname + '/views');
      app.set('view engine', 'jade');
  
      app.use(express.favicon());
      app.use(express.methodOverride());
      app.use(express.csrf());
  
      app.use(require('less-middleware')({ src: __dirname + '/public', compress: true }));
      app.use(express.static(path.join(__dirname, 'public')));
      app.use(function(req, res, next) {
          res.locals._csrf = req.session._csrf;  //THIS COULD BE THE SOURCE OF THE PROBLEM
          return next();
      })
  
      app.use(app.router);
  
  
      app.use(express.session({ secret: 'Bigsecretscretsecret' })); 
      app.use(passport.initialize());
      app.use(passport.session()); 
      app.use(flash()); 
  
  });
  
  
  require('./app/routes.js')(app, passport); 
  
  
  app.listen(port);
  console.log('Go to' + port);
  </code></pre>