Skip to content

fix(bearer-auth): mention verifyToken in missing-options error message - #4987

Merged
yusukebe merged 1 commit into
honojs:mainfrom
tan7vir:fix/bearer-auth-error-message
Jun 1, 2026
Merged

yusukebe merged 1 commit into
honojs:mainfrom
tan7vir:fix/bearer-auth-error-message

Conversation

@tan7vir

@tan7vir tan7vir commented May 31, 2026

Copy link
Copy Markdown
Contributor

The bearerAuth middleware accepts either a token or a verifyToken option, and throws when neither is provided. However, the error message only mentions "token":

throw new Error('bearer auth middleware requires options for "token"')

This is misleading for users who intend to use verifyToken — the guard fires precisely when neither option is present, so the message should mention both. This also makes the message consistent with the sibling auth middlewares, which already list every accepted option:

  • basic-auth: 'basic auth middleware requires options for "username and password" or "verifyUser"'
  • jwk: 'JWK auth middleware requires options for either "keys" or "jwks_uri" or both'

This PR updates the message to:

throw new Error('bearer auth middleware requires options for "token" or "verifyToken"')

and adds a test that asserts the new message (it fails against the previous message and passes with this change).

Author should do the following, if applicable

  • Add tests
  • Run tests
  • Double-check your code matches Hono's coding style

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.79%. Comparing base (2cbeadd) to head (fbdc558).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4987   +/-   ##
=======================================
  Coverage   78.78%   78.79%           
=======================================
  Files         154      154           
  Lines       10578    10578           
  Branches     2215     2215           
=======================================
+ Hits         8334     8335    +1     
+ Misses       2244     2243    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe yusukebe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe

yusukebe commented Jun 1, 2026

Copy link
Copy Markdown
Member

@tan7vir

Thanks! This is a good improvement. Looks good.

@yusukebe
yusukebe merged commit 413d3cb into honojs:main Jun 1, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants