nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.44k stars 7.6k forks source link

Wrapper code for eliminating authentication boilerplate #10231

Closed KevinMusgrave closed 2 years ago

KevinMusgrave commented 2 years ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

Most applications don't need custom authentication code. Something standard with reasonable defaults would be fine. There is documentation for authentication, but it's a lot of boilerplate, and copying all of this boilerplate is not ideal.

Describe the solution you'd like

It would be great if nestjs provided a separate package like @nestjs/auth that wrapped all of the boilerplate, so that authentication could be taken care of with a few lines of code.

People who want a custom approach could keep all their existing boilerplate, while people who want a "reasonable default" could install @nestjs/auth and use the wrapper.

Teachability, documentation, adoption, migration strategy

-

What is the motivation / use case for changing the behavior?

-

micalevisk commented 2 years ago

the issue is that the authentication can be done by several 3rd-party libs. The docs only shows an integration with passport

So the @nestjs/auth would be a wrapper for @nestjs/passport (which is a wrapper for passport lol) or what?

KevinMusgrave commented 2 years ago

It seems like I have to copy-paste:

It'd be nice if I could just import AuthModule from nestjs/auth, and pass in some basic configuration options.

micalevisk commented 2 years ago

I'm not sure if we could have a flexible wrapper around this :thinking: I believe that the intention of @nestjs/password is to avoid boilerplate set up already, we could improve it instead, I guess

micalevisk commented 2 years ago

or maybe you could write a builder around that pattern and publish it as a community nestjs lib

Nestjs users don't need to use passport. Having yeat another but generic-named (@nestjs/auth) package would be too inflexible, to me.

We could add some sort of builder for that boilerplate setup in @nestjs/passport. I don't know how feasible it is tho

kamilmysliwiec commented 2 years ago

Thanks for your suggestion!

This has been discussed in the past and we decided to not implement it in the foreseeable future.

If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.