PUT request on `/user` fails because of lines 7-9 of user.decorator.ts
Opened this issue · 1 comments
Deleted user commented
I don't understand the purpose of that block, but what I know is that the PUT request works if I comment those lines of code.
The error is about getting the user's id as undefined.
if (!!req.user) {
return !!data ? req.user[data] : req.user;
}
lujakob commented
This decorator gets the user object. Initially it took it from the request property user, which is added by the auth middleware
https://github.com/lujakob/nestjs-realworld-example-app/blob/master/src/user/auth.middleware.ts#L25
Afterwards I found out that in some routes authentication is optional. I need the user, even though the route is not protected. As auth middleware only adds the user if the route is protected, I added it manually in line 13. So line 7-10 is redundant I guess...