-
Notifications
You must be signed in to change notification settings - Fork 340
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
Force emails to be unique with mongo #51
Conversation
This change forces user email addresses to be unique by using mongoose's unique constraint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work okay, but not sure why generateHash was moved from out of the else to before if(err)... maybe it doesn't really matter but I would think it would make more sense to keep generateHash inside the else because then if the user already exists then the server won't have to perform the unnecessary password hash computation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just add a small clarifying comment 🙂 @DaleMitchell makes a good point, but I'm indifferent towards whether you want to move that into the else
because it's a small optimization and it seems slightly easier to read / neater to set the email and password in the same place. Up to you!
u.password = User.generateHash(password); | ||
u.save(function(err){ | ||
if (err){ | ||
if (err.name === 'MongoError' && (err.code === 11000 || err.code === 11001)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment here about what the hard-coded error codes mean?
It doesn't make sense to move the generatePassword into the else. It would require another db save, which would ultimately be less efficient. |
Mmm, you're right. Thanks Pat! |
The more I know then 😄 |
Why not add a debounce to the login/signup page as well? |
Force emails to be unique with mongo
Force emails to be unique with mongo
Force emails to be unique with mongo
During HackMIT 2017, we found multiple users with the same email address. This can happen if a user hits register repeatedly. This change forces user email addresses to be unique by using mongoose's unique constraint.