Basic auth — Middleware · Hono

Put a username and password in front of the admin routes with basicAuth(), on a path prefix and on a single route, and let the handler know who signed in.

What you will learn

Read the theory for Basic auth

All Middleware lessons

All Hono courses

loading types…

What you'll learn

  • Guard a path prefix with basicAuth({ username, password, realm }) and read the 401 and WWW-Authenticate challenge a browser reacts to
  • Check credentials your own way with verifyUser, and answer refusals with your own message
  • Hand the authenticated user to the handler with onAuthSuccess and c.set()