Passport.js is a beautiful authentication middleware for node.js, but getting it right is hard for the first time. I am going to point to my own repo: https://github.com/sjuvekar/3Dthon/tree/master/auth to refer to how I did it the last time. Basic stages are simple:
- Include appropriate strategies (local/Facebook/Google oauth etc)
- Define a callback function under each strategy to create appropriate mongoDB user object, insert it into database or flash an appropriate error msg ( connect-flash is useful here) and redirect to appropriate route.
- Finally, define appropriate route like /auth/google/callback and call passport.authenticate("google") etc inside it.
Here's a link to passport js
just in case.