Guides  ›  Lifecycle  ›  Early returns ← PREV NEXT →

Early returns

Return nothing to continue. Return a value to stop the route chain.

module.exports = {
  paths: '/private',
  middleware: [function (state) {
    if (state.req.query.access !== 'yes') {
      state.res.statusCode = 403
      return 'Access denied'
    }
  }],
  handler: function (state) {
    return 'Welcome'
  }
}

This example demonstrates control flow. For authentication, see Basic auth. null, false, 0, and '' also stop the chain. After and done hooks still run.

Next: Errors →

Tools for business systems.