Kyl*_*son 7 node.js async-await passport-local passport.js
我一直未能获得passport.authenticate在async/await或promise模式下工作.这是一个我认为应该工作的例子,但它无法执行passport.authenticate().
const passport = require("passport");
let user;
try {
user = await __promisifiedPassportAuthentication();
console.log("You'll never have this ", user);
} catch (err) {
throw err;
}
function __promisifiedPassportAuthentication() {
return new Promise((resolve, reject) => {
console.log("I run");
passport.authenticate('local', (err, user, info) => {
console.log("I never run");
if (err) reject(err);
if (user) resolve(user);
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何智慧的圣言都会受到高度赞赏.
只是让任何其他疲惫的程序员遇到这个..
function __promisifiedPassportAuthentication() {
return new Promise((resolve, reject) => {
passport.authenticate('local', (err, user, info) => {
...
})(req, res) // <-- that guy right there
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4255 次 |
| 最近记录: |