fix(passwordless): Reduce db calls, run in parallel
Adds validations, reduces the number of database calls, separates concers. reduces logic
This commit is contained in:
committed by
mrugesh mohapatra
parent
44c2eb65d5
commit
750c9f1eab
21
server/boot/extend-request.js
Normal file
21
server/boot/extend-request.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import _ from 'lodash';
|
||||
import http from 'http';
|
||||
import { Observable } from 'rx';
|
||||
import { login } from 'passport/lib/http/request';
|
||||
|
||||
// make login polymorphic
|
||||
// if supplied callback it works as normal
|
||||
// if called without callback it returns an observable
|
||||
// login(user, options?, cb?) => Void|Observable
|
||||
function login$(...args) {
|
||||
if (_.isFunction(_.last(args))) {
|
||||
return login.apply(this, args);
|
||||
}
|
||||
return Observable.fromNodeCallback(login).apply(this, args);
|
||||
}
|
||||
|
||||
module.exports = function extendRequest() {
|
||||
// see: jaredhanson/passport/blob/master/lib/framework/connect.js#L33
|
||||
http.IncomingMessage.prototype.login = login$;
|
||||
http.IncomingMessage.prototype.logIn = login$;
|
||||
};
|
Reference in New Issue
Block a user