Search⌘ K
AI Features

Solution: Create the About and Dashboard Routes

Understand how to implement public and protected routes in AdonisJs by creating an About page and a dashboard route secured with custom middleware that only allows authenticated users to access it.

We'll cover the following...

Solution

The following is the complete implementation of the problem described here:

'use strict'

class ConvertEmptyStringsToNull {
  async handle ({ request }, next) {
    if (Object.keys(request.body).length) {
      request.body = Object.assign(
        ...Object.keys(request.body).map(key => ({
          [key]: request.body[key] !== '' ? request.body[key] : null
        }))
      )
    }

    await next()
  }
}

module.exports = ConvertEmptyStringsToNull

Press Run and wait for the output to ...