gpt4 book ai didi

javascript - 类型错误 : done is not a function

转载 作者:行者123 更新时间:2023-11-29 21:05:31 27 4
gpt4 key购买 nike

我在我的项目中使用 passport.js 来验证和处理 session 。

我使用电子邮件从 Passport 进行身份验证,但是当在验证时调用 done 时,我收到错误 done is not a function。

at Promise.<anonymous> (/Users/sultan/Desktop/too2/controllers/users.js:39:28)
at Promise.<anonymous> (/Users/sultan/Desktop/too2/node_modules/mongoose/lib/promise.js:120:8)

代码

  // LOCAL LOGIN =============================================================
passport.use('local-login', new LocalStrategy({
usernameField : 'email',
passwordField : 'password'
//passReqToCallback : true // allows us to pass in the req from our route (lets us check if a user is logged in or not)
},
function( email, password, done) {
if (email)
email = email.toString().toLowerCase();

// asynchronous
process.nextTick(function() {
User.findOne({ email: email }, function(err, user) {
// if there are any errors, return the error
if (err)
return done(err);

// if no user is found, return the message
if (!user)
//(/Users/sultan/Desktop/too2/controllers/users.js:39:28)
return done(null, false, {message: 'No user found.'});

if (!user.validPassword(password))
return done(null, false, {message: 'Oops! Wrong Password'});

// all is well, return user
else
return done(null, user);
});
});

}));

此错误的原因是什么,我该如何解决?

最佳答案

这对我有用

passport.use('login', new LocalStrategy({
// by default, local strategy uses username
usernameField : 'email',
passwordField : 'password',
passReqToCallback : true
},
function(req, email, password, done) {
if (email) email = email.toLowerCase();

// asynchronous
process.nextTick(function() {
User.findOne({ 'email' : email }, function(err, user) {
// if there are any errors, return the error
if (err)
return done(err);

// if no user is found, return the message
if (!user)
return done(null, false, req.flash('loginMessage', 'No user found.'));

if (!user.validPassword(password))
return done(null, false, req.flash('loginMessage', 'Oops! Wrong password.'));

// all is well, return user
else
return done(null, user);
});
});

}));

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

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