Skip to content

Commit 7dab896

Browse files
committed
Merge branch 'release-2.12.9' into develop
2 parents aa0db22 + c077141 commit 7dab896

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "p5.js-web-editor",
3-
"version": "2.12.8",
3+
"version": "2.12.9",
44
"description": "The web editor for p5.js.",
55
"scripts": {
66
"clean": "rimraf dist",

server/models/user.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ userSchema.statics.findByUsername = function findByUsername(
266266

267267
/**
268268
*
269-
* Queries User collection using email or username.
269+
* Queries User collection using email or username with optional callback.
270270
* This function will determine automatically whether the data passed is
271271
* a username or email, unless you specify options.valueType
272272
*
@@ -276,30 +276,37 @@ userSchema.statics.findByUsername = function findByUsername(
276276
* default query for username or email, defaults
277277
* to false
278278
* @param {("email"|"username")} options.valueType - Prevents automatic type inferrence
279+
* @callback [cb] - Optional error-first callback that passes User document
279280
* @return {Promise<Object>} - Returns Promise fulfilled by User document
280281
*/
281282
userSchema.statics.findByEmailOrUsername = function findByEmailOrUsername(
282283
value,
283-
options
284+
options,
285+
cb
284286
) {
285-
const isEmail = options?.valueType
286-
? options.valueType === 'email'
287-
: value.includes('@');
288-
289-
const query = isEmail ? { email: value } : { username: value };
290-
const queryOptions = {
291-
collation: { locale: 'en', strength: 2 },
292-
maxTimeMS: 10000 // Set a timeout of 10 seconds to help prevent long-running queries
293-
};
294-
const queryPromise = this.findOne(query, queryOptions).exec();
295-
287+
let isEmail;
288+
if (options && options.valueType) {
289+
isEmail = options.valueType === 'email';
290+
} else {
291+
isEmail = value.indexOf('@') > -1;
292+
}
296293
// do the case insensitive stuff
297-
// TODO: Handling options should be figured out. At the moment, I think scenarios where it's currently used can be case insensitive?
298-
// if (options?.caseInsensitive) {
299-
// return queryPromise;
300-
// }
301-
302-
return queryPromise;
294+
if (
295+
(arguments.length === 3 && options.caseInsensitive) ||
296+
(arguments.length === 2 &&
297+
typeof options === 'object' &&
298+
options.caseInsensitive)
299+
) {
300+
const query = isEmail ? { email: value } : { username: value };
301+
return this.findOne(query)
302+
.collation({ locale: 'en', strength: 2 })
303+
.exec(cb);
304+
}
305+
const callback = typeof options === 'function' ? options : cb;
306+
if (isEmail) {
307+
return this.findByEmail(value, callback);
308+
}
309+
return this.findByUsername(value, callback);
303310
};
304311

305312
/**

0 commit comments

Comments
 (0)