Node.js 向车把模板公开flash消息

Node.js 向车把模板公开flash消息,node.js,backbone.js,handlebars.js,passport.js,Node.js,Backbone.js,Handlebars.js,Passport.js,我正在构建一个SPA:Backbone.js、Node.js、Mongo。我正在使用Passport.js进行身份验证,我想知道如何将req.flash变量公开到我的Handlebar模板中?在本例中,如果用户尝试使用已接收的电子邮件登录,我希望在我的视图中公开flash变量“signupMessage” 在my Express服务器中: app.use(function(req, res, next){ res.locals.flash = req.flash next(); })

我正在构建一个SPA:Backbone.js、Node.js、Mongo。我正在使用Passport.js进行身份验证,我想知道如何将req.flash变量公开到我的Handlebar模板中?在本例中,如果用户尝试使用已接收的电子邮件登录,我希望在我的视图中公开flash变量“signupMessage”

在my 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);
            });
        }

        });    

    });

}));