0
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
},
(req, email, password, done) => {
// asynchronous
// User.findOne wont fire unless data is sent back
process.nextTick(() => {
// 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({ '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, {'errorMessages': 'That email is already taken.'});
} else {
// if there is no user with that email
// create the user
let newUser = new User();
// set the user's local credentials
newUser.name = req.body.fullname;
//newUser.email = email;
newUser.password = newUser.generateHash(password);
// save the user
newUser.save((err)=>{
if (err)
return done(err);
return done(null, newUser);
});
}
});
});
}));
上記のコードはパスポートjs認証を使用するノードjsにあり、ローカルサインアップのコードは機能していません。上記のコードでUser.findOne()は関数ではありません
私はエラーを取得しています:
User.findOne() is not a function
。
私のスキーマは、あなたが(あなたがまだいないのであれば)model
var UserDetails = mongoose.model('userInfo', UserDetail);
を使用してデータのインスタンスを作成する必要が
どのように我々はUser'が何であるかを '知っているはずですか? –