Should nodeify handle additional parameters for callbacks
See original GitHub issueI asked a question on StackOverflow seeking help with dealing with the callback for a passport.js strategy callback.
The strategy callback allows an optional parameter which can be used as a flash message.
// This strategy is used by passport to handle logins
module.exports.localStrategy = new LocalStrategy(function(username, password, done) {
users.findOneAsync({username: username}).bind({})
.then(function(user) {
if (!user) {
throw new NoMatchedUserError('Incorrect username.');
//should be equivalent to:
// return done(null, false, {message:'something'});
}
this.user = user;
return compare(password, user.password);
})
.then(function(isMatch) {
if (isMatch) {
return this.user;
//is equivalent to:
// return done(null, this.user);
}
else {
throw { message: 'Incorrect password.' };
//should be equivalent to:
// return done(null, false, {message:'something else'};
}
})
.nodeify(done);
});
Benjamin Gruenbaum suggested on that question that this might be a feature worth adding in
My JS chops fall way short of knowing where to start on implementing this so apologies for suggesting work for others! Really interested to watch commits to see the shape this might take…
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to pass a third argument to a callback using Bluebird.js ...
by calling nodeify(done) I can handle the path where passwords match but I don't know how to pass the optional third parameter out...
Read more >How to deal with nested callbacks and avoid “callback hell”
The callback will always have two arguments. And these arguments are in the same order. (Error first, followed by whatever you're interested in) ......
Read more >ROS2 rclpy Parameter Callback [Tutorial]
Learn how to use a rclpy parameter callback in ROS2. ... Hence we need to add a callback to notify the node as...
Read more >then/nodeify: Convert promised code to use node style callbacks
Call nodeify directly passing the promise and an optional callback as arguments. If a callback is provided it will be called as callback(error,...
Read more >Callback Functions in JavaScript - Impressive Webs
This method accepts two arguments: The speed of the fade-in and an optional callback function. In that function you can put whatever you ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Implemented for 2.0