In this section, we will implement authentication on our app, to ensure that only registered users can carry out certain operations. To set up authentication, we need to implement the following:
- User registration and login: This involves creating views and actions for users to sign up and then log in to the application
- Authentication middleware: This involves implementing middleware to restrict and grant access to certain resources based on the visitor's authentication status
Before we can implement registration and login, however, we need to register our body parser plugin, which will enable us to retrieve form data. We can easily do this in the index.js file, as shown here:
// ./index.js
// ...
const bodyParser = require('koa-body');
app.use(bodyParser());
// ...