Guides  ›  State helpers  ›  Basic auth ← PREV NEXT →

Basic auth

Return state.basicauth() from middleware.

module.exports = {
  paths: '/private',
  middleware: [function (state) {
    return state.basicauth({
      username: 'admin',
      password: process.env.ADMIN_PASSWORD
    })
  }],
  handler: function (state) {
    return 'Welcome'
  }
}

Success returns undefined and continues. Failure sets 401 and WWW-Authenticate, then returns null.

Next: Timer →

Tools for business systems.