无法在node.js中设置undefined的属性

时间:2015-07-21 16:12:04

标签: javascript node.js

我从这里获取了代码:

link

错误快照:

snapshot

我在newUser.local.email = email;收到错误 这段代码:

 passport.use('local-signup',
    new LocalStrategy({
        // by default, local strategy uses username and password, we will override with email
        usernameField : 'email',
        passwordField : 'password',
        passReqToCallback : true // allows us to pass back the entire request to the callback
    },
 function(req, email, password, done) {

        // asynchronous
        // User.findOne wont fire unless data is sent back
        process.nextTick(function() {

        // find a user whose email is the same as the forms email
        // we are checking to see if the user trying to login already exists
        User.findOne({ 'local.email' :  email }, function(err, user) {
            // if there are any errors, return the error
            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.'));
            } 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);

                // save the user
                newUser.save(function(err) {
                    if (err)
                        throw err;
                    return done(null, newUser);
                });
            }

        });    

        });

    }));

样本------>楷模。  我有User.js,其中包含用户注册的架构。 看起来像这样:

var userSchema = new mongoose.Schema({
  email: String,
  password: String,

});

这里看错了什么?我可以获得一些指示吗?

0 个答案:

没有答案