Before implementing authentication, we need to set up a session middleware for our application. This will help us store data relating to each browser session, and we will be using to store user details for each logged-in user.
To help us handle sessions, we will be using the koa-session middleware. To register it, let's update the ./index.js file as shown:
// ./index.js
// ...
const session = require('koa-session');
app.keys = ['secret key'];
app.use(session(app));
// ...
Registering the koa-session middleware makes the ctx.session object available throughout our app, making it possible for us to use it to store and retrieve session data per user.