Adding the Passport middleware
As mentioned earlier, we use Passport to deal with user authentication in our API. Here, we will see how to use and store sessions and encrypt a user password to maintain a secure authentication.
First of all, let's install and save the Passport middleware to the application:
- Open the terminal and type the following command:
npm install passport passport-local --save
- Place the following code after the
app
express variable:// Passport configuration require('./server/config/passport')(passport);
- Now, we need to create a
passport.js
file and the necessary code inside theconfig
folder. We can name this file with any name. However, to demonstrate the use of thepassport
module, we use the same name from the module. Create ...
Get Learning Single-page Web Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.