-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Adds username support #154
Conversation
@divyanshu-rawat Please review. |
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.
Please address the left comment & resolve codacy
errors.
} = req; | ||
try { | ||
const userObject: InterfaceUserModel | null = await User.findOne({ email }); | ||
const userObject: InterfaceUserModel | null = await User.findOne({ $or: [ { email }, { userName } ] }); |
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.
do you really think we need or operator here, as described in schema username
is unique
so DB will throw an error if username/ email
is not unique? and I think in your case it won't even go to userName, as email will never be null. Let me know your thought on it, or correct me if I am wrong.
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.
Ok so I have put an or condition for a case like this. Let's assume we already have a user { ashu, [email protected]} . This particular condition would prevent a user { ashu, [email protected]} , {ashuK, [email protected]} and { ashu, [email protected]} from registering. This condition ensures uniqueness of both email and username for a new user. In login controller, this same condition ensures the user can either login with user name or email.
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.
I just modified the query. I think we need the userObject for socialLoginCheck function.
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.
Yeah looks good, didn't know about $or
operator, though my intitution was defining unique
in schema ensures uniqueness
of both email and username for a new user.
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.
LGTM, but this can only be merged once we have functionality on client side to send the username
as it is required property. I can add that if you want, else you can also pick up the task, let me know your thoughts on it :)
} = req; | ||
try { | ||
const userObject: InterfaceUserModel | null = await User.findOne({ email }); | ||
const userObject: InterfaceUserModel | null = await User.findOne({ $or: [ { email }, { userName } ] }); |
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.
Yeah looks good, didn't know about $or
operator, though my intitution was defining unique
in schema ensures uniqueness
of both email and username for a new user.
Closes #152