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

Validate token

Every HTTP request has to send the JWT in its authorization header. The express-jwt middleware will check whether a valid token has been passed. If so, the request will continue its flow, otherwise the backend will respond with an unauthorized exception.

Go ahead and apply the following changes to the admin-api.js file:

...const Match = require('../models/match')const auth =require('express-jwt')const updateScore = async (matchId, teamId) => {  ...}api  .route('/admin/match/:id?')  .post(auth({ secret: 's3cret'}),  (req, res, next) => {    ...  })...

First, we start importing the express-jwt module and instantiate a new constant called auth. Secondly, we use the auth function and pass a JSON object that has the secret attribute; we ...

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