Sudeep's Blog

Disorganized Thoughts in Organized Manner

passport.js and authentication
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: to refer to how I did it the last time. Basic stages are simple:
  1. Include appropriate strategies (local/Facebook/Google oauth etc)
  2. 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.
  3. 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.
Back to Home