June 2018
Intermediate to advanced
348 pages
8h 19m
English
We will use an NPM module to generate JWT called jsonwebtoken. Open a new console and write the following command into the wc-backend folder to install the module:
$ npm install jsonwebtoken --save
Once the installation is finished. Open security-api.js, and let's import our library, as follows:
const express = require('express')const jwt = require('jsonwebtoken')const api = express.Router()...
With our dependency imported in our file, let's implement the generateToken function. Apply the following changes:
...const logIn = (username, password) => { if (username == 'admin' && password == 'admin') { let userData = { name: "Admin" } return generateToken(userData) } else { return null } }const generateToken = userData ...Read now
Unlock full access