9 Replies
What happens when you use this?
https://labs.convex.dev/auth/authz#authenticate-http-actions
Authorization - Convex Auth
Authentication library for your Convex backend
have not tried this yet but I want to create some http endpoints that do not care about the auth and I want to use hono as it has nice interface to parsing urls etc, but I could not manage to make it work when I have auth setup in my http.ts file.
Hmm, the hono router doesn't layer very well with the built-in router.
Some form of this should get you to a working setup, we'll need more time to think about how to ideally combine these:
I didn't test this, or even typechecked it, but maybe you can make it work?
@Michal Srb Any more thoughts on this? I can get everything with hono working great, but the /.well-known/openid-configuration and /.well-known/jwks.json paths from convex auth routes don't play well and always return null for the user
I did a test of the above as well and there is a type error on c.req when calling httpAction
Argument of type 'HonoRequest<"/.well-known/jwks.json", unknown>' is not assignable to parameter of type 'Request'.
Type 'HonoRequest<"/.well-known/jwks.json", unknown>' is missing the following properties from type 'Request': cache, credentials, destination, headers, and 10 more.ts(2345)
@cameronm try to typecast
c.req as any
There's also a different method for mounting the hono router inside the normal convex router: https://stack.convex.dev/hono-with-convex#extending-routes-using-the--prefix
Advanced HTTP Endpoints: Convex ❤️ Hono
Adding advanced HTTP Endpoint functionality by extending Convex with Hono.
@Michal Srb Actually the above code you shared works to ensure the auth routes resolve correctly with the hono router 😀 .
RE that article. So if I am understanding the second method in that article correctly, we are basically passing any incoming http requests to the hono router with the action context?
Yeah. It's a flipped approach. In the code I shared, we ask the hono router to route the specific routes to the built-in router.
In the article, we ask the built-in router to route the other routes to the hono router. (ofc you'd need to add the logic for not routing the auth routes to hono)
Ah cool, ok. I'll play around with both approaches to see which mental model works better for me lol. Thanks for your help!