JSON Web Tokens — Middleware · Hono

Issue a signed token at login with sign() and guard the API with jwt(): the token carries who the caller is and what they may do, and the server trusts it without a lookup.

What you will learn

Read the theory for JSON Web Tokens

All Middleware lessons

All Hono courses

loading types…

What you'll learn

  • Sign a token with sign(payload, secret) and read its three parts
  • Guard routes with jwt({ secret, alg }) and read the verified claims from c.get('jwtPayload')
  • Tell the refusals apart: no token, a token that fails verification, and a valid token whose claims are not enough