-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Integrate Passport.js with Hono via Connect Middleware Compatibility
Description
The goal is to enable robust, standard authentication in Hono applications by using the popular and mature passport.js library. This would allow developers to leverage its extensive ecosystem of over 500 authentication strategies.
Problem
Hono does not natively support the (req, res, next) function signature used by Connect/Express middleware, which passport.js and its strategies rely on. Currently, integrating Passport.js requires complex, unofficial adapters or reimplementations of the Passport pattern, such as the hono-passport library we investigated. This creates a significant barrier to adoption for developers accustomed to the Node.js ecosystem.
A potential official solution is being developed in honojs/middleware#928, which introduces a compatibility layer for Connect middleware. This would be the ideal path forward.
Impact
- Developers cannot easily use a standard, battle-tested authentication solution like Passport.js.
- The lack of a simple integration forces developers to write boilerplate code or rely on unofficial, potentially unmaintained packages.
- Migrating existing Node.js applications that use Passport.js to Hono is significantly more difficult.
Tasks
- Monitor the progress and merging of the Connect compatibility layer in feat: middleware for compatibility with express/connect for Hono honojs/middleware#928.
- Once the middleware is released, create an official example or guide demonstrating the integration of
passport.jswith Hono using the newconnectadapter. - The example should include:
- Setting up the
connectadapter. - Initializing Passport.js (
passport.initialize()). - Implementing a session-based strategy (e.g.,
passport-local) withpassport.session(). - Defining login, logout, and protected routes within a Hono application.
- Setting up the
- Verify that Passport's
req.user,req.login(), andreq.logout()functions work as expected through the compatibility layer. - Update the Hono documentation to establish this as the official method for using Passport.js, effectively deprecating the need for third-party adapters.
Expected Outcomes
- A clear, documented, and official way to use
passport.jsand its vast ecosystem of strategies within Hono applications. - Authentication in Hono becomes simpler and more standardized, lowering the barrier for developers migrating from the Express ecosystem.
- The need for complex, unofficial adapters is eliminated.
Additional Notes
- This approach is dependent on the release of the
connectmiddleware adapter. - Successfully integrating Passport.js will also serve as a benchmark for the
connectcompatibility layer, proving its effectiveness for a wide range of other popular Express/Connect middleware.