TypeError:done不是Passport函数

时间:2017-10-21 05:05:40

标签: javascript node.js passport.js

passport.use('local.signup', new Localstrategy({
    usernameField: 'email',
    passwordField: 'password',
    roleField: 'role',
    passReqToCallback: true
}, function(req, email, password, role, done) {
    req.checkBody('email', 'Invalid Email').notEmpty().isEmail();
    req.checkBody('password', 'Invalid Password ').notEmpty().isLength({min:4});
    req.checkBody('role', 'Invalid Password').notEmpty();
    var errors = req.validationErrors();
    if (errors) {
        var messages = [];
        errors.forEach(function(error) {
            messages.push(error.msg);
        });
        return done(null, false, req.flash('error', messages));
    }
    // what the...
    User.findOne({
        'email': email
    }, function(err, user) {
        if (err) {
            return done(err);
        }
        if (user) {
            return done(null, false, {
                message: 'Email is already in use.'
            });
        }
        var newUser = new User();
        newUser.email = email;
        newUser.password = newUser.encryptPassword(password);
        newUser.role = role;
        newUser.save(function(err, result) {
            if (err) {
                return done(err);
            }
            return done(null, newUser);
        });
    });
}));

1 个答案:

答案 0 :(得分:0)

我不相信这个设置会做任何事情:

roleField: 'role',

您可以通过更改函数参数来修复错误:

function(req, email, password, role, done) {

到此:

function(req, email, password, done) {