Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用bluebird承诺将参数传递给passport策略回调?_Javascript_Node.js_Promise_Passport.js_Bluebird - Fatal编程技术网

Javascript 如何使用bluebird承诺将参数传递给passport策略回调?

Javascript 如何使用bluebird承诺将参数传递给passport策略回调?,javascript,node.js,promise,passport.js,bluebird,Javascript,Node.js,Promise,Passport.js,Bluebird,我在努力保证。我对promises和passport都是新手,我非常依赖它,它使用bluebird的Promise库将附加参数传递给passport的done()回调。此注释产生了一个处理其他回调参数的函数,但我无法在自己的代码中使用它: const passport = require('passport'); const User = require('../models/user'); const LocalStrategy = require('passport-local'); con

我在努力保证。我对promises和passport都是新手,我非常依赖它,它使用bluebird的Promise库将附加参数传递给passport的
done()
回调。此注释产生了一个处理其他回调参数的函数,但我无法在自己的代码中使用它:

const passport = require('passport');
const User = require('../models/user');
const LocalStrategy = require('passport-local');
const NoMatchedUserError = require('../helpers/error_helper').NoMatchedUserError;
const NotActivatedError = require('../helpers/error_helper').NotActivatedError;

const localOptions = { usernameField: 'email' };
const localLogin = new LocalStrategy(localOptions, function(email, password, done) {

  let user;

  User.findOne({ email: email }).exec()
    .then((existingUser) => {
      if (!existingUser) { throw new NoMatchedUserError('This is not a valid email address.'); }
      user = existingUser;
      return user.comparePassword(password, user.password);
    })
    .then((isMatch) => {
      if (!isMatch) { throw new NoMatchedUserError('This is not a valid password.'); }
       return user.isActivated();
    })
    .then((isActivated) => {
      if (!isActivated) { throw new NotActivatedError('Your account has not been activated.'); }
      return user;
    })
    .asCallback(done, { spread: true });
});
用户能够毫无问题地进行验证。我遇到的问题是身份验证失败:
done(null,false,{message:'message'}
显然没有在
.asCallback
方法中调用。我非常确定这与抛出错误有关,因此我尝试使用以下方法:

if (!existingUser) { return [ false, { message: 'This is not a valid email address.' } ]; }
但是返回数组也不起作用,因为它会沿着承诺链传递并破坏代码


有什么想法吗?

有什么解决办法吗?