i have a problem about the controllers
yoohan-dex opened this issue · 3 comments
yoohan-dex commented
@Post(':slug/favorite')
async favorite(@Headers('authorization') authorization: string, @Param('slug') slug) {
return await this.articleService.favorite(this.getUserIdFromToken(authorization), slug);
}
@Delete(':slug/favorite')
async unFavorite(@Headers('authorization') authorization: string, @Param('slug') slug) {
return await this.articleService.unFavorite(this.getUserIdFromToken(authorization), slug);
}
like this section is it feels like have a tiny redundance.
I mean that can auth be taken in middleware like koa, and we don't need to pay attention to it?
lujakob commented
@yoohan-dex Good point. I've refactored the code. Now I add the userId in the authentication middleware and get it in the controller from the request object. Thanks.
https://github.com/lujakob/nestjs-realworld-example-app/blob/master/src/user/auth.middleware.ts#L25
yoohan-dex commented
emmm..I haven’t tried this framework just learning from you. Is it now the user object could be wrapped in a new decorator?
2018年2月24日 +0800 PM8:51 Lukas Jakob <notifications@github.com>,写道:
@yoohan-dex<https://github.com/yoohan-dex> Good point. I've refactored the code. Now I add the userId in the authentication middleware and get it in the controller from the request object. Thanks.
https://github.com/lujakob/nestjs-realworld-example-app/blob/master/src/user/auth.middleware.ts#L25
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#1 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AHNwuOWnlSUhpJCug5JYx6H4gaIZlWy4ks5tYAXDgaJpZM4SRs5M>.
lujakob commented
Yeah, even better. I didn't see the section custom decorators yet.