诺言创build,但不是从返回。 Knex / Bookshelf

每当我点击需要validation的路由时,我在控制台中都会收到警告消息。

(node:940)警告:在xxxxxx \ app \ config \ passport.js:15:19中的处理程序中创build了一个承诺,但未从其返回,请参阅http://bluebirdjs.com/docs/warning-explanations。 html#warning-a-promise-was-created-in-a-handler-but-was-not-returned-from-it at .fetch(xxxxxx \ node_modules \ bluebird \ js \ release \ method.js:13:13 )

我configuration了这样的护照:

const JwtStrategy = require('passport-jwt').Strategy; const ExtractJwt = require('passport-jwt').ExtractJwt; const secret = process.env.SECRET; var opts = {} function passportConfig(db, passport) { opts.jwtFromRequest = ExtractJwt.fromAuthHeader(); opts.secretOrKey = secret; passport.use(new JwtStrategy(opts, payloadCallback.bind(null, db))); } function payloadCallback(db, payload, done) { new db.User({id: payload}).fetch() .then(response => response.toJSON()) .then(user => done(null, user)) .catch(err => console.log(err)); } module.exports = passportConfig; 

任何帮助,将不胜感激。

我解决了这个警告,通过replace第二个然后捕获.asCallback(完成)。

 const JwtStrategy = require('passport-jwt').Strategy; const ExtractJwt = require('passport-jwt').ExtractJwt; const secret = process.env.SECRET; var opts = {} function passportConfig(db, passport) { opts.jwtFromRequest = ExtractJwt.fromAuthHeader(); opts.secretOrKey = secret; passport.use(new JwtStrategy(opts, payloadCallback.bind(null, db))); } function payloadCallback(db, payload, done) { new db.User({id: payload}).fetch() .then(response => response.toJSON()) .asCallback(done); } module.exports = passportConfig;