O'Reilly logo

Hands-On Full Stack Web Development with Aurelia by Erikson Haziz Murrugarra Sifuentes, Diego Jose Arguelles Rojas

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

Generating the token

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 ...

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