0
你好,所以我在我的passport.js下面的代碼:不能在passport.js傳遞的參數 - MEAN堆棧
passport.use('local-signup', new LocalStrategy({
// by default, local strategy uses username and password, we will override with email
usernameField : 'email',
passwordField : 'password',
nameField: 'fullname',
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, done, fullname) {
// 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 = password;
newUser.local.fullname = fullname;
newUser.local.role = "default";
// save the user
newUser.save(function(err) {
if (err) {
throw err;
}
console.log(newUser);
return done(null, newUser);
});
}
});
});
}));
,我需要保存全稱到數據庫但遺憾的是不添加因爲是完成後的最後一個參數。但是如果在完成之前生病了,那麼返回的結果是沒有找到,並給我一個應用程序崩潰。
您認爲什麼是解決方案?
你不能只從'req'參數中得到全名(nameField)嗎? – lipp
不,我不能,我只是試過。 – NinetyHH