Nest: [Documentation] Authentication sample doesn't match docs, needs more info

Created on 18 May 2018  路  9Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[*] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

The guide over at https://docs.nestjs.com/techniques/authentication has some concept of a users model for authentication, however the sample at https://github.com/nestjs/nest/tree/master/sample/19-auth is totally barebones and only uses a hardcoded email.

Likewise, the authentication page doesn't provide a lot of information about some very common use cases for authentication (Though it's somewhat assisted by https://docs.nestjs.com/guards & https://docs.nestjs.com/custom-decorators)

Expected behavior

I understand the sample is supposed to be extremely storage-agnostic, but perhaps some example could be done that's entirely in memory? It'd be great to see the following:

  • Update the sample to match the example in the authentication docs with a user model
  • Provide example login / logout endpoints
  • Provide an endpoint that is guarded against being unauthenticated, and have it return your user
  • (Maybe) provide an example of persisting the auth token in some way

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

Authentication is a pretty core part of web apps, I think this would be very worthwhile to flesh out.

core type potential issue 馃挃

Most helpful comment

This is even more complicated, because in version v4, forRoutes accept a string, an object of { path, method } <- this was freaking useful, and whole controller. @kamilmysliwiec could you revert this change to accept back again the { path, method } object?

Imagine situation like that:

/auth/token <- POST
/auth/token <- GET

When you're doing POST you might not need to setup some middleware for that route, but only for GET now this is impossible to achieve that. But it was, and was useful as hell.

Regards.

All 9 comments

until the docs are updated, you can check out my repo https://github.com/bojidaryovchev/nest-angular/tree/master/src/server/modules/auth

@bojidaryovchev Your solution does not seem to work in V5

I know that, I've reported it already in an issue.. Generally the consumer.apply(middleware).forRoutes(string) in v5 doesnt work, it only works if u pass a controller and we are therefore unable to configure middlewares for a single route.. I'm waiting for it to be resolved and a patch version to be published in order to update it.. The idea is the same tho

Excellent. Thanks!

@bojidaryovchev i have the same trouble, and waiting for solution too

684 is related

This is even more complicated, because in version v4, forRoutes accept a string, an object of { path, method } <- this was freaking useful, and whole controller. @kamilmysliwiec could you revert this change to accept back again the { path, method } object?

Imagine situation like that:

/auth/token <- POST
/auth/token <- GET

When you're doing POST you might not need to setup some middleware for that route, but only for GET now this is impossible to achieve that. But it was, and was useful as hell.

Regards.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

2233322 picture 2233322  路  3Comments

rlesniak picture rlesniak  路  3Comments

thohoh picture thohoh  路  3Comments

janckerchen picture janckerchen  路  3Comments

artaommahe picture artaommahe  路  3Comments