Skip to content

Integrate Passport.js with Hono via Connect Middleware Compatibility #34

@mridang

Description

@mridang

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

  1. Monitor the progress and merging of the Connect compatibility layer in feat: middleware for compatibility with express/connect for Hono honojs/middleware#928.
  2. Once the middleware is released, create an official example or guide demonstrating the integration of passport.js with Hono using the new connect adapter.
  3. The example should include:
    • Setting up the connect adapter.
    • Initializing Passport.js (passport.initialize()).
    • Implementing a session-based strategy (e.g., passport-local) with passport.session().
    • Defining login, logout, and protected routes within a Hono application.
  4. Verify that Passport's req.user, req.login(), and req.logout() functions work as expected through the compatibility layer.
  5. 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.js and 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 connect middleware adapter.
  • Successfully integrating Passport.js will also serve as a benchmark for the connect compatibility layer, proving its effectiveness for a wide range of other popular Express/Connect middleware.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions