-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(users): User email to accept null regardless of unique #1145
Conversation
Provider Twitter (refer twitter.js file) is not producing an email address on callback. When two different users signs up using twitter the second user will not be able to sign up if the first user didn't set the email address manually. This is due to the error of email already exist, in actual terms this is the null value which is conflicting the unique constraint.
@codydaig @ilanbiala @lirantal any updates or comments? |
@farajfarook can you give an example of what the data look like when you have the error and what the data look like with this PR? |
@farajfarook Does this http://stackoverflow.com/questions/7955040/mongodb-mongoose-unique-if-not-null describe what you're attempting to fix with this change? For a change like this, since it's model related, I think we should have tests accompany this PR. Side Note: |
@ilanbiala it doesn't change any way in which data is stored in the DB. It simply accepts the creation of the second user who is having the email as null. Forget providers and twitter, just refer the code
It accepts blanks and also it's unique. - In the sense, it's not accepting two documents with the blank values to be stored in email field. @mleanos Yes you are right. And yes I can properly authenticate with twitter. But the problem comes when the second user tries to authenticate with twitter. |
@farajfarook I think what @ilanbiala was asking, and I'm curious too, is what the User data looks like when this error occurs. Is the I'm wondering if we even want to add the Would it be better to just remove the |
@farajfarook I just tested my suggested fix, and it didn't work. I just removed the I then implemented your fix, and was able to resolve the issue. One potential hiccup that I read about, and experience with my testing, is that if the I think this is probably fine for a framework, but may cause some confusion or problems for users that upgrade an existing application with this fix. @ilanbiala @codydaig @rhutchison Any thoughts? After testing this, and doing some more research I think this is a good use for the |
@farajfarook @mleanos if that is the case, will reindexing fix the issue? |
@farajfarook Did you decide against this fix? Have you resolved the issue in a different way? |
@ilanbiala To get the
This seems like a rather painless process for someone to perform. I would like it for this option to be implemented. I came across this issue again as I was working on a bug I found in our GitHub passport strategy implementation. It's the exact scenario that @farajfarook is describing with Twitter. In our GitHub strategy, we're not handling a case where the email field could empty/null/missing from the API response. There's a simple fix for it, but I think it should be coupled with adding the I'm going to submit a PR for the fix since it doesn't look like this PR will be re-submitted. @farajfarook I apologize that I didn't recognize this to be the proper fix when you originally submitted this PR. I just didn't have enough information to know if it was the wise choice for us. I really appreciate you bringing this to our attention and introducing the |
Fixes an issue with an empty/missing/null Email coming from GitHub's OAuth call response. Also, introduces the `sparse` index option on the User model's Email field. This will ensure that we can have multiple User documents without the Email field. Adds a server-side User model test for the sparse index setting on the email field. Confirms that User documents without the email field are not indexed, illustrating the sparse option on the schema's email field works properly. Added the dropdb task to the Gulp test:client & test:server tasks, to ensure we have a clean database & that any indexes are rebuilt; this will ensure any Schema changes (in this case the email index is rebuilt using the sparse index option) are reflected when the database is started again. Added a UPGRADE.md for tracking important upgrade information for our user's to be aware of, when we introduce potentially breaking changes. Included an explanation of the Sparse index being added, and how to apply it to an existing MEANJS application's database. Adds a script for dropping the `email` field's index from the User collection. Related meanjs#1145
Fixes an issue with an empty/missing/null Email coming from GitHub's OAuth call response. Also, introduces the `sparse` index option on the User model's Email field. This will ensure that we can have multiple User documents without the Email field. Adds a server-side User model test for the sparse index setting on the email field. Confirms that User documents without the email field are not indexed, illustrating the sparse option on the schema's email field works properly. Added the dropdb task to the Gulp test:client & test:server tasks, to ensure we have a clean database & that any indexes are rebuilt; this will ensure any Schema changes (in this case the email index is rebuilt using the sparse index option) are reflected when the database is started again. Added a UPGRADE.md for tracking important upgrade information for our user's to be aware of, when we introduce potentially breaking changes. Included an explanation of the Sparse index being added, and how to apply it to an existing MEANJS application's database. Adds a script for dropping the `email` field's index from the User collection. Related #1145
Provider Twitter (refer
twitter.js
file) is not producing an email address on callback. When two different users signs up using twitter the second user will not be able to sign up if the first user didn't set the email address manually.This is due to the error of email already exist, in actual terms this is the
null
value which is conflicting the unique constraint.