I'm getting the following error while using Node.js and Express. Here are my versions :
Node : v0.8.8
Express: 3.0.0rc3
The following error is obtained while trying to access the page :
TypeError: Object #<IncomingMessage> has no method 'flash'
at routes (/Users/nblavoie/Desktop/HotPie/HotPie/apps/authentication/routes.js:23:8)
I've tried to remove the app.use(app.router); from the app.js with no success. Here is the code that causes the error. See req.flash line.
app.post('/sessions', function(req, res)
{
if(req.body.user == 'piechief'
&& req.body.password == '12345')
{
req.session.currentUser = req.body.user;
req.flash('info', "You're logged in as #{req.session.currentUser}");
res.redirect("/login");
return;
}
else
{
req.flash('error', "Those credentials were incorrect. Try again.");
res.redirect("/login");
return;
}
});
Here is the interesting part of my app.js :
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
secret: "DBBD6BE563419EDB0E5CBD228E603D4AD232CE05434B4FA95C6908B64EA515C3",
store: new RedisStore({
host: "127.0.0.1",
port: "6379",
db: "mydb"
})
}));
app.use(app.router);
app.use(express.static(path.join(__dirname, '/public')));
});
Any idea please? I've took a loof at the Express'flash documentation and I can't see what I'm doing wrong.
req.flash
has been removed as of 3.0:
req.flash()
(just use sessions:req.session.messages = ['foo']
or similar)- connect-flash can be used as middleware to provide req.flash()
This solved it for me
https://github.com/jaredhanson/passport/issues/61
Now my passport app.configure looks like this:
app.configure(function (){
app.use(express.cookieParser('keyboard cat'));
app.use(express.session({ cookie: { maxAge: 60000 }}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
})