June 2018
Intermediate to advanced
348 pages
8h 19m
English
Let's create a simple authentication logic. The backend expects a username and password with the value of the administrator. If these values are provided, it will return a valid token; otherwise, it will return null. Apply the following changes to the code:
const express = require('express')const api = express.Router()const logIn = (username, password) => { if (username === 'admin' && password === 'admin') { const userData = { name: "Admin" } return generateToken(userData) } return null}api...
The code is very straightforward. First, we compare the value in a simple if conditional, and we created a userData object, which will contain the user information, in this case just a name value is provided. Finally, we ...
Read now
Unlock full access