-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Authentication improvements - OAuth Login #1511
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
Changes from 6 commits
69ea487
5edee7e
c12f0cd
ac6a5a8
156b2ad
e5f5a2e
050b3ed
bb8c4a2
170e201
bcf25c1
e6fd441
919d15c
7290600
0bc8958
3694e8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ const userSchema = new Schema({ | |
| verifiedToken: String, | ||
| verifiedTokenExpires: Date, | ||
| github: { type: String }, | ||
| google: { type: String }, | ||
| email: { type: String, unique: true }, | ||
| tokens: Array, | ||
| apiKeys: { type: [apiKeySchema] }, | ||
|
|
@@ -170,14 +171,21 @@ userSchema.statics.findByEmail = function findByEmail(email, cb) { | |
| * Queries User collection by username and returns one User document. | ||
| * | ||
| * @param {string} username - Username string | ||
| * @param {Object} [options] - Optional options | ||
| * @param {boolean} options.caseInsensitive - Does a caseInsensitive query, defaults to false | ||
| * @callback [cb] - Optional error-first callback that passes User document | ||
| * @return {Promise<Object>} - Returns Promise fulfilled by User document | ||
| */ | ||
| userSchema.statics.findByUsername = function findByUsername(username, cb) { | ||
| userSchema.statics.findByUsername = function findByUsername(username, options, cb) { | ||
| const query = { | ||
| username | ||
| }; | ||
| return this.findOne(query, cb); | ||
| if ((arguments.length === 3 && options.caseInsensitive) | ||
| || (arguments.length === 2 && typeof options === 'object' && options.caseInsensitive)) { | ||
| return this.findOne(query).collation({ locale: 'en', strength: 2 }).exec(cb); | ||
| } | ||
| const callback = typeof options === 'function' ? options : cb; | ||
| return this.findOne(query, callback); | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -187,15 +195,26 @@ userSchema.statics.findByUsername = function findByUsername(username, cb) { | |
| * a username or email. | ||
| * | ||
| * @param {string} value - Email or username | ||
| * @param {Object} [options] - Optional options | ||
| * @param {boolean} options.caseInsensitive - Does a caseInsensitive query rather than | ||
| * default query for username or email, defaults | ||
| * to false | ||
| * @callback [cb] - Optional error-first callback that passes User document | ||
| * @return {Promise<Object>} - Returns Promise fulfilled by User document | ||
| */ | ||
| userSchema.statics.findByEmailOrUsername = function findByEmailOrUsername(value, cb) { | ||
| userSchema.statics.findByEmailOrUsername = function findByEmailOrUsername(value, options, cb) { | ||
| // do the case insensitive stuff | ||
| const isEmail = value.indexOf('@') > -1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We validate usernames not containing "@" chars in the client but I wonder whether this should also happen in the mongoose User model?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean validating a username when saving a (new or existing)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! Just to ensure these username rules are respected at the core of the app. |
||
| if ((arguments.length === 3 && options.caseInsensitive) | ||
| || (arguments.length === 2 && typeof options === 'object' && options.caseInsensitive)) { | ||
| const query = isEmail ? { email: value } : { username: value }; | ||
| return this.findOne(query).collation({ locale: 'en', strength: 2 }).exec(cb); | ||
| } | ||
| const callback = typeof options === 'function' ? options : cb; | ||
| if (isEmail) { | ||
| return this.findByEmail(value, cb); | ||
| return this.findByEmail(value, callback); | ||
| } | ||
| return this.findByUsername(value, cb); | ||
| return this.findByUsername(value, callback); | ||
| }; | ||
|
|
||
| /** | ||
|
|
||
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'm a bit confused about when this flow will be triggered? If the user does not have an Editor account with the same email as their Github account?
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.
It's expected that this would trigger when a user is registering for the Editor with a GitHub account, i.e. they clicked "Login with GitHub" from the Signup Page.
This just reminded me that I should test if linking social accounts works properly if the email they registered with for the Editor is different from the email for their GItHub/Google Account.