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

The authentication REST controller

We have already defined the route that will be responsible to make our logic available as a REST endpoint, so the only step required is to call our logIn function. Go ahead and apply the following change:

...const generateToken = (userData) => {   return jwt.sign(userData, "s3cret", { expiresIn: '3h' })}api  .route('/auth')  .post((req, res, next) => {    let { username, password } = req.body    let token = logIn(username, password)    if (token) {        res.send(token)    } else {        next(new Error("Authentication failed"))    }  })module.exports = api

First, we extract the username and password from the req.body object. After that, we call the logIn function and host the result in the token variable. If the token is not null, 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