gpt4 book ai didi

javascript - Passportjs 类型错误 : undefined is not a function

转载 作者:行者123 更新时间:2023-12-03 07:35:50 25 4
gpt4 key购买 nike

我见过其他人遇到同样的问题并查看了他们的解决方案,但我不确定他们是否有帮助。我似乎无法使用在线注释和简单的日志语句来调试我的代码。我是 Express 和 Passport 的新手,因此我将不胜感激任何帮助或有用的链接。

这是代码、依赖项和错误。

错误:passportjs TypeError:未定义不是函数 ->> return done(null, user) 是错误所在的行

依赖关系:

"body-parser": "^1.10.2",
"cookie-parser": "~1.3.3",
"express": "~4.11.1",
"express-session": "^1.10.3",
"hjs": "~0.0.6",
"mongodb": "^1.4.40",
"monk": "*",
"morgan": "^1.5.1",
"passport": "^0.2.1",
"passport-local": "^1.0.0",
"serve-favicon": "^2.2.0",

文件名 PASSPORT.JS

    passport.use('local-signup', new LocalStrategy({

// by default, local strategy uses username and password, we will override with email
usernameField: 'username',
passwordField: 'password',
passReqToCallback: true // allows us to pass back the entire request to the callback
},
function (req, res, email, password, done) {
var db = req.db;
var companyName = req.body.companyName;
var fname = req.body.fname;
var email = req.body.email;
var username = req.body.username;
//var lname = req.body.lname;
//var phone = req.body.phone;
var password = req.body.password;

// Check if any field has been left blank
console.log('check if fields filled');
if (fname === '' || companyName === '' || email === '' || username === '' || password === '' ) {
console.log('Is this working????');
res.render('business/register', {
error: 'You must fill in all fields.',
fname: fname,
companyName: companyName,
email: email,
username: username,
password: password
});
} else {
console.log('grab data from database');
var businesses = db.get('businesses');
var employees = db.get('employees');
//TODO: Get visitors too
//var visitors = db.get('visitors');
//var staff = db.get('staff');
//var

// 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
businesses.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) {
console.log('user exists');
console.log(user);
return done(null, false);
} else {

// if there is no user with that email
// create the user
console.log('creating user');
// set the user's local credentials
password = auth.hashPassword(password);

// save the user
businesses.insert({
email: email,
password: password,
companyName: companyName,
//phone: phone,
fname: fname,
username: username,
//lname: lname,
logo: '',
walkins: false
}, function (err, result) {
if (err) {
throw err;
}

var businessID = result._id.toString();

employees.insert({
business: ObjectId(businessID),
password: result.password,
//phone: result.phone,
fname: result.fname,
//lname: result.lname,
email: result.email,
smsNotify: true,
emailNotify: true,
admin: true
},function(err, user){
if (err) {
throw err;
}
console.log(user);
//error is right here
return done(null, user);
});
});
}
});
}

}
));`

最佳答案

您的处理程序回调有一个无效的额外 res 参数。它的签名应该是:

function(req, email, password, done)

关于javascript - Passportjs 类型错误 : undefined is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35618841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com