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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using jwt middleware and I've set it up so it works on the routes I want to protect. I set
exppayload timestamp to be short to test my route. When the token expires, or when it's completely missing, the middleware returns401code 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 thejwtmiddleware. I'm not sure if it's possible to somehow wire up combine function that would intercept the response from thejwtmiddleware and called redirect.I realize I could write my own custom middleware which calls
verifyfromhono/jwtand 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.onErrorbut I wanted the functionality to be bundled in one place.Beta Was this translation helpful? Give feedback.
All reactions