jaredhanson / passport-facebook

Facebook authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-facebook/?utm_source=github&utm_medium=referral&utm_campaign=passport-facebook&utm_content=about
MIT License
1.29k stars 446 forks source link

Syntax for Sails for Facebook Authentication #187

Open jaddoescad opened 7 years ago

jaddoescad commented 7 years ago

I used the sails framework to authenticate a user with my custom facebook token strategy. It works perfectly. I copied this snippet of code from github to make it work, However, I don't quite understand the syntax of that last part which has (req, res); at the end. Obviously it's referring to request and response, but why is that line of code there, it seems to be in an awkward place. Authentication fails if I exclude that line of code. It must be important so I just need to figure out what it is doing .

module.exports = {
 facebook: function(req, res) {
passport.authenticate('facebook-token', function(error, user, info) {
  res.ok();
})
(req, res);
}
  };
dariooddenino commented 7 years ago

Hi :) passport.autheticate is a middleware and it expects req, res and possibly next as arguments. Here you're passing them to it through a closure