lucia-auth / lucia

Authentication, simple and clean
https://lucia-auth.com
BSD Zero Clause License
9.65k stars 500 forks source link

[Feature Request]: Integrate HTTP middleware in the API thanks to `universal-middleware` #1704

Closed magne4000 closed 1 month ago

magne4000 commented 1 month ago

Package

lucia

Goals

  1. Officially support many servers through HTTP middleware
  2. Widen the documented servers and frameworks supported list with the help of universal-middleware
  3. Currently supported targets:
    • Hono
    • Express
    • Hattip
    • Webroute
    • Fastify
    • h3
    • Cloudflare
  4. A unique middleware implementation supporting all above targets, and more on the way

Background

lucia-auth HTTP middlewares are currently only documented and not part of the API. Also, current documentation lacks supports for popular servers, such as Hono. Supporting those middlewares is non trivial, time consuming and bug-prone, and I assume those are the main reasons that they are currently not part of the API.

Proposal

I created universal-middleware with the goal to alleviate those specific issues for library authors. You can think of it as unplugin for HTTP middlewares.

By creating a universal standard-based middleware, you can support any servers and frameworks supported by universal-middleware.

As an example, batijs.dev already supports lucia-auth thanks to universal-middleware. You can check the middlewares and handlers that are currently implemented, and their usage in express for instance.

universal-middleware can also auto-compile directly any universal middleware and handler to all its supported targets. I invite you to take a look at the documentation examples, so that you can see how easy it would be for users to use such compiled middlewares.

magne4000 commented 1 month ago

cc @pilcrowOnPaper

pilcrowonpaper commented 1 month ago

Implementing each middleware is trivial and I don't see really see it as a problem to solve. Don't want to add more maintenance burden to the project either