0

I am trying to use connect-flash with sails.js, according to middleware documentation of sailsjs http://sailsjs.org/documentation/concepts/middleware , this is what I did

passportInit    : require('passport').initialize(),
passportSession : require('passport').session(),
flash           : require('connect-flash'),

order: [
  'startRequestTimer',
  'cookieParser',
  'session',
  'passportInit',
  'passportSession',
  'flash',
  'myRequestLogger',
  'bodyParser',
  'handleBodyParserError',
  'compress',
  'methodOverride',
  'poweredBy',
  '$custom',
  'router',
  'www',
  'favicon',
  '404',
  '500'
]

and this is how my AuthController.js looks ( as I am using connect-flash with passport )

module.exports = {

_config: {
    actions: false,
    shortcuts: false,
    rest: false
},

'login': function(req, res,next) {

    passport.authenticate('local', { successRedirect: '/user/dashboard',
        failureRedirect: '/login',
        failureFlash: true })(res,req,next);
},

'logout': function(req, res) {
    req.logout();
    res.redirect('/');
}

};

But after adding flash in the queue pages never finish loading and it never renders. Please can anybody assist me with this? I am not sure how to make this work. Thanks in advance.

mshahbazm
  • 611
  • 1
  • 11
  • 23

2 Answers2

1

I've had more success with Express' flash module.

In my config/http.js:

middleware : {
  flash : require('flash')(),
  ...
  order : [
    ...
    'passportInit',
    'passportSession',
    'flash',
    'bodyParser',
    ...
  ],
  ...
}
0

I spent quite some time and was not able to get this package working with sales, I am sure I must be missing something, However I found another package sails-hook-flash that is plug and play for sails app.

mshahbazm
  • 611
  • 1
  • 11
  • 23