将Flash消息暴露给Handlebars模板

我正在构buildSPA:Backbone.js,Node.js,Mongo。 我使用Passport.js进行身份validation,并想知道如何将req.flashvariables暴露给我的Handlebars模板? 在这种情况下,如果用户试图用电子邮件login,我想在我的视图中公开flashvariables“signupMessage”。

在我的Express服务器上:

app.use(function(req, res, next){ res.locals.flash = req.flash next(); }); 

护照本地策略:

 passport.use('local-signup', new LocalStrategy({ usernameField : 'email', passwordField : 'password', petnameField : 'petname', passReqToCallback : true // allows us to pass back the entire request to the callback }, function(req, email, password, done) { process.nextTick(function() { User.findOne({ 'local.email' : email }, function(err, user) { if (err) return done(err); // check to see if theres already a user with that email if (user) { return done(null, false, req.flash('signupMessage', 'That email is already taken.')); console.log('need to update now'); } else { // if there is no user with that email // create the user var newUser = new User(); // set the user's local credentials newUser.local.email = email; newUser.local.password = newUser.generateHash(password); newUser.local.petname = req.body.petname; newUser.kittenType = req.body.kittenType; // save the user newUser.save(function(err) { if (err) throw err; return done(null, newUser); }); } }); }); })); 

       

网上收集的解决方案 "将Flash消息暴露给Handlebars模板"