Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add official Express.js support to auth/core #8257

Closed
hillac opened this issue Aug 8, 2023 · 7 comments 路 Fixed by #8354
Closed

Add official Express.js support to auth/core #8257

hillac opened this issue Aug 8, 2023 · 7 comments 路 Fixed by #8354
Labels
accepted The feature request is considered. If nobody works actively on it, feel free to. enhancement New feature or request

Comments

@hillac
Copy link
Contributor

hillac commented Aug 8, 2023

Description 馃摀

I've seen several issues / posts related to support for express.js and want to use it myself. I would like to propose adding express as an officially supported framework. Given the intention to support more frameworks, I think it would be worthwhile bringing direct support for Auth.js to the most popular back end javascript framework.

Here is an example implementation: rexfordessilfie/authjs-express-demo, which implements a translation layer for the web standard api request/response to express requests/responses, and express middleware for JWT authentication. So support seems quite straightforward.

I'd be willing help with this / add documentation for using express. If this feature is not accepted, I'm also happy to just write docs for using it like in authjs-express-demo if anyone else considers that worthwhile.

Some links to related issues:

For older versions:

On reddit:

How to reproduce 鈽曪笍

https://github.com/rexfordessilfie/authjs-express-demo

Contributing 馃檶馃徑

Yes, I am willing to help implement this feature in a PR

@hillac hillac added enhancement New feature or request triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Aug 8, 2023
@rexfordessilfie
Copy link
Contributor

Thanks for putting this issue together @hillac! As the creator of the demo repository I would also love to see official support and community efforts on the logic required to translate between Web Request/Response APIs and Express' APIs. I have brought it to a working state in my repository, but more hands and eyes on it would improve its quality and make it more useful to the community.

I think being added as a frameworks-express (e.g exposing a router that could be plugged into Express) could be the best path towards this, but also docs/a guide, or even a stand-alone library could also achieve similar! I would appreciate thoughts from maintainers and the community on this!

Thanks!

@balazsorban44
Copy link
Member

balazsorban44 commented Aug 10, 2023

As far as I can tell, all we need is a wrapper around @auth/core that transforms Request -> Response to Node.js' req and res. The linked demo has that already, nice work!

If someone opens a PR, we could discuss further there.

As for documentation, we prefer JSDoc, that we can then use to auto-generate our docs site.

See https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/index.ts for an example. Rendered here: https://authjs.dev/reference/core

Looking forward to @auth/express

@balazsorban44 balazsorban44 added accepted The feature request is considered. If nobody works actively on it, feel free to. and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Aug 10, 2023
@rexfordessilfie
Copy link
Contributor

Thank you for the comments and guidance @balazsorban44 馃檶! You鈥檙e right, the translation wrapper should be all that is needed, and is taken care of in the demo!

@hillac, what do you say to pairing together to put together a PR for review and discussion?

We can follow closely, the standard setup in frameworks-x directories, and follow the approach from the demo.

Also @balazsorban44, there were some more specific pieces such as having a body parser middleware in the app to make the translation fully possible. I will call these out in the JSDoc and PR to make sure we鈥檇 be taking the right approach there.

Thanks to you both again 馃憤!

@hillac
Copy link
Contributor Author

hillac commented Aug 11, 2023

Yep sounds good.

@binaryartifex
Copy link

cant' tell you how much im looking forward to drop kicking passportjs in my nestjs application in favor of this....

@matmar-91
Copy link

Thank you for working on this! 鉂わ笍
Any progress so far?馃

@hillac
Copy link
Contributor Author

hillac commented Jan 3, 2024

Thank you for working on this! 鉂わ笍 Any progress so far?馃

It's pretty much done #8354.
But no word from the maintainers on it since August so I'm not sure when it will happen. You can just use the index and http-api-adapters files directly in your project for now, it's only a bit over 100 lines, so you can easily audit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The feature request is considered. If nobody works actively on it, feel free to. enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants