O'Reilly logo

Learning Single-page Web Application Development by Fernando Monteiro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. Open the terminal and type the following command:
    npm install passport passport-local --save
    
  2. Place the following code after the app express variable:
    // Passport configuration
    require('./server/config/passport')(passport);
  3. Now, we need to create a passport.js file and the necessary code inside the config folder. We can name this file with any name. However, to demonstrate the use of the passport module, we use the same name from the module. Create ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required