Full-Stack Web Development with Vue.js and Node

(singke) #1
Building Authentication with passport.js Chapter 6

With these in place, we should now be able to access all the routes directly. We can also
reload the pages now.


Since we are building our Vue.js components and running our app solely
on the Node.js server, whenever we make a change to the Vue.js
components, we will need to build the application again with the npm
run build command.

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:



  1. Add necessary routes for Local authentication.

  2. Add a middleware method to check whether authentication is successful.


Let's dive into the details for each of the preceding steps.

Free download pdf