Passport's Local Strategy
Passport's Local Strategy is easy to integrate. As always, let's start with the installation of this strategy as follows.
Installing Passport's Local Strategy
We can install passport's Local Strategy by running the following command:
$ npm install passport-local --save
The following code should add the package to your package.json file:
...
"node-sass": "^4.7.2",
"nodemon": "^1.14.10",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
...
Configuring Passport's Local Strategy
There are a few steps to configure the Passport's Local Strategy. We will discuss each step in detail:
- Add necessary routes for Local authentication.
- Add a middleware method to check whether authentication is successful.
Let's dive into the details for each of the preceding steps.
Adding necessary routes for Local Authentication
Let's go ahead and add the necessary routes when we click on the login button. Replace the contents of controllers/users.js
with the following code:
const User = require('../models...