Replies: 2 comments 2 replies
-
Although it is not mentioned in the documentation, you can use it this way. import { Hono } from "hono"
import { jwt, decode,verify } from "hono/jwt"
import { HTTPException } from "hono/http-exception"
new Hono().get(
"/",
async (c, next) => {
const token = c.req.header("authorization")?.split(" ")[1]
if (!token) {
throw new HTTPException(403)
}
const { header, payload } = decode(token)
// When you're ready, validate it.
const verifiedPayload = await verify(token, "secret")
return await next()
},
// Of course, you can also let the JWT middleware validate it.
jwt({
secret: "secret",
}),
(c) => c.text("hi"),
) |
Beta Was this translation helpful? Give feedback.
2 replies
-
You can use a combine middleware import { except, some } from 'hono/combine';
app.use(some(jwt({ secret }), () => true)); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have a route which accepts both auth/unauth requests. I would like to use the JWT middleware cause I use access Tokens but the JWT seems to early return if the user is unauthed but rather I would like to have an an optional jwtPayload then.
Is that in some way supported?
Beta Was this translation helpful? Give feedback.
All reactions