You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using jwt middleware and I've set it up so it works on the routes I want to protect. I set exp payload timestamp to be short to test my route. When the token expires, or when it's completely missing, the middleware returns 401 code with Content-Type: text. I think that is fine, however I'm using hono as an application server that renders HTML.
This means I would like to redirect to sign-in form when 401 (or even 403) happens. I don't think this is possible out of the box with the jwt middleware. I'm not sure if it's possible to somehow wire up combine function that would intercept the response from the jwt middleware and called redirect.
I realize I could write my own custom middleware which calls verify from hono/jwt and performs this logic, but I wanted to use this middleware and not rely on custom solutions unless I need it. I feel like I'm missing something here.
I know I could handle an exception globally with app.onError but I wanted the functionality to be bundled in one place.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am using jwt middleware and I've set it up so it works on the routes I want to protect. I set
exp
payload timestamp to be short to test my route. When the token expires, or when it's completely missing, the middleware returns401
code withContent-Type: text
. I think that is fine, however I'm using hono as an application server that renders HTML.This means I would like to redirect to sign-in form when
401
(or even403
) happens. I don't think this is possible out of the box with thejwt
middleware. I'm not sure if it's possible to somehow wire up combine function that would intercept the response from thejwt
middleware and called redirect.I realize I could write my own custom middleware which calls
verify
fromhono/jwt
and performs this logic, but I wanted to use this middleware and not rely on custom solutions unless I need it. I feel like I'm missing something here.I know I could handle an exception globally with
app.onError
but I wanted the functionality to be bundled in one place.Beta Was this translation helpful? Give feedback.
All reactions