I have an expressjs application and I am trying to get passportjs set up for simple user authentication. My routes are stored in a separate file. I have a routes file (users.js) for all my user related routes. I also have a controller file called UserController that contains all the functions for user related stuff and deals with my database.
My question is, where should I declare the passport strategy so that it follows the MVC pattern?
Putting it in any other file besides the routes file doesn't work as it does not have the passport object.
I put my passport file in a config folder. Here is an example of a passport.js file. This is for the local-login strategy.
then in app.js I do:
then in your routes file:
now your passport functions are available in your route. I would search 'easy-node-authentication' for good examples on the web.