Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax for Sails for Facebook Authentication #64

Open
jaddoescad opened this issue Dec 2, 2016 · 3 comments
Open

Syntax for Sails for Facebook Authentication #64

jaddoescad opened this issue Dec 2, 2016 · 3 comments

Comments

@jaddoescad
Copy link

jaddoescad commented Dec 2, 2016

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); 
  }
     };
@ghaiklor
Copy link
Collaborator

ghaiklor commented Dec 2, 2016

@jadslim313 passport.authenticate() returns a function, which accepts req and res arguments. When you are using it in Express middlewares, it calls automatically. But, in Sails, you need to call it by yourself.

@ghost
Copy link

ghost commented Dec 6, 2016

That makes sense ! I ended up removing res only having (req) in there. It worked just as fine, which makes sense as the token is in the request. However, what would the purpose of res be in this case? Just to make sure I'm not missing anything.

@ghaiklor
Copy link
Collaborator

ghaiklor commented Dec 6, 2016

@rslim087g you can remove res, I leave it just for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants