I've been failing to get passport.authenticate to work at all inside of an async/await or promise pattern. Here is an example I feel should work, but it fails to execute 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);
}
}
}
Any sage words of wisdom would be greatly appreciated.
Just incase any other tired programmer out there encounters this..
function __promisifiedPassportAuthentication() {
return new Promise((resolve, reject) => {
passport.authenticate('local', (err, user, info) => {
...
})(req, res) // <-- that guy right there
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With