Customizing Bearer Authentication Middleware Responses #3346
-
In general I want my API to return json responses also in case of errors, invalid requests or if a resource does not exist. I'm using the Bearer Authentication Middleware and it works nicely, except that it returns a text response in case of invalid token or if the authorization header was not provided at all. I would like to send a response like below if e.g. the token was not provided, instead of the general "Bad Request" response from the middleware.
Would this be possible already? Or would it be better to create my own middleware to achieve this? @yusukebe would you be open to be able to customize the response in the current middleware? In that case I have some ideas and I could provide a PR. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
The hono-rate-limiter has a quite nice approach for doing something similar. https://github.com/rhinobase/hono-rate-limiter/blob/main/packages/core/src/core.ts#L40C1-L50C7
The Hono Bearer Authentication Middleware is a bit different as it return a
|
Beta Was this translation helpful? Give feedback.
-
@yusukebe I was thinking something like below. So instead of currently in Bearer Authentication Middleware:
it could be something like:
|
Beta Was this translation helpful? Give feedback.
I prefer: