Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs + passport + express 3.0 + connect-flash no flashing?

I'm using a passport-local strategy for authenticate users. I followed the guide given by Jared Hanson and installed connect-flash in order to give flash method to the req object. So one of my request handlers is the following:

 app.post('/login',                             
      passport.authenticate('local', {           
          successRedirect: '/'                   
        , failureRedirect: '/login'              
        , successFlash: 'Bienvenido'             
        , failureFlash: 'Credenciales no válidas'                             
      })                                         
  );   

When the user login fails, it redirects the user to /login again but it doesnt flash anything :/

UPDATE: I use mongodb for session storage and I see this:

> db.sessions.find()
{ "_id" : "qZ2eiTnx6r9LR25JOz/TGhiJ", "session" : "{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{\"user\":\"4ffb5b5db9cc16b615000001\"},\"flash\":{\"error\":[\"Credenciales no válidas\"],\"success\":[\"Bienvenido\"]}}" }

So the messages are inserted into the session object but they aren't pulled out. Should I do something special?

like image 379
Dredok Avatar asked Jul 09 '12 21:07

Dredok


1 Answers

I assume you're pulling the messages out and rendering them in a view? Something like:

app.get('/login', function(req, res){
  res.render('login', { message: req.flash('error') });
});
like image 95
Jared Hanson Avatar answered Oct 23 '22 18:10

Jared Hanson