Rubyae
Rubyae
HHono
Created by Rubyae on 5/18/2024 in #help
Combine JWT middleware with other middleware
I have a file made /middleware/jwt.ts:
import { Context, Next } from 'hono';
import { jwt } from 'hono/jwt';

export default function(c: Context<any, string, {}>, next: Next) {
const jwtMiddleware = jwt({
secret: process.env.JWT_SECRET!
});

return jwtMiddleware(c, next);
}
import { Context, Next } from 'hono';
import { jwt } from 'hono/jwt';

export default function(c: Context<any, string, {}>, next: Next) {
const jwtMiddleware = jwt({
secret: process.env.JWT_SECRET!
});

return jwtMiddleware(c, next);
}
Now I'm trying to make a different middleware that checks if the user has certain roles but for this I require the jwtPayload provided by the above middleware now I can do the following:
app.post('/', jwt, requireRoles([UserRole.Moderator, UserRole.Manager]), async (c) => {});
app.post('/', jwt, requireRoles([UserRole.Moderator, UserRole.Manager]), async (c) => {});
but it's kind of obvious that if you need to use requireRoles, jwt is also used so I'd like to use the jwt middleware inside the requireRoles middleware. Is this not possible or how should I do this? Because with everything I try I can't seem to make it work 🤔
7 replies
HHono
Created by Rubyae on 4/14/2024 in #help
Hono Oauth Provider with JWT issue
No description
9 replies