Passport JS passport.use在exports.function中不起作用

时间:2016-06-24 09:11:55

标签: javascript node.js passport.js

来自passportJS的HelloStrategy Hello无法运作:

    exports.checkIt = function(req, res, next){
    passport.use(new LocalStrategy(
        function(username, password, done){
            console.log(username);
            models.User.findOne({username: username}, function(err, user){
                if(err) throw err;
                if(!user){
                    return done(null, false, { message: 'Unknown User' });
                }
                var bcrypt = require('bcryptjs');
                bcrypt.compare(req.body.password, password, function(err, isMatch){
                    if(err) throw err;
                    if(isMatch){
                        return done(null, user);
                    } else {
                        return done(null, false, { message: 'Invalid Password' });
                    }
                })
            })
        }
    ));

    passport.serializeUser(function(user, done){
        done(null, user.id);
    });

    passport.deserializeUser(function(id, done){
        models.User.findById(id, function(err, user){
            done(err, user);
        });
    });

    passport.authenticate('local', { successRedirect: '/obs', failureRedirect: '/connection', failureFlash: true });
};

从路线调用CheckIt:app.post(' / connection',auth.checkIt);

" console.log(用户名)"没有出现在控制台中。

0 个答案:

没有答案