Skip to content

How to properly change user object #653

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eikaramba opened this issue Oct 22, 2014 · 4 comments
Closed

How to properly change user object #653

eikaramba opened this issue Oct 22, 2014 · 4 comments
Labels

Comments

@eikaramba
Copy link

Let's say i have a field for the user model called "fullname".

If i now get the user object by req.user, change req.user.fullname and call user.save(...) the password hash will rehashed, resulting that the password is garbesh and not valid anymore.

Of course i could manually remove the password field everytime before i save the user object (because the pre save hook for "save" checks whether this field is there or not). Also only updating the field via User.update(...) is possible. However maybe there are better ways how to handle that. Can the field per default be omittet? So that is must be set explicity if one want to change the password?

@JaKXz
Copy link
Collaborator

JaKXz commented Oct 24, 2014

Have you tried something like:

router.put('/users/:id', auth.isAuthenticated(), controller.update);

in your server/api/user/index.js? Or am I misunderstanding your question?

@JaKXz JaKXz added the question label Oct 24, 2014
@eikaramba
Copy link
Author

Mhm i guess yes you misunderstand the problem ;) You know let's say i fetch a user object via mongoose and the call save() on that very same object, it would rehash the password. Maybe it is feasible to exclude the password from the query result, but on the other hand this might be lead to problems when you actually need the password. I can close this issue if you think this is not really a problem, but at least i spend some time figuring out why the password hash changed everytime i did some actions on the website.

@JaKXz
Copy link
Collaborator

JaKXz commented Oct 25, 2014

Is the problem related to #569 [and the other issues mentioned there]?

@eikaramba
Copy link
Author

Good catch! Yes you are right, i guess i should then close this issue. But at least i now know i'm not the only one with this problem/question :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants