Files
freeCodeCamp/server/boot/extend-request.js
Berkeley Martinez 750c9f1eab fix(passwordless): Reduce db calls, run in parallel
Adds validations, reduces the number of database calls, separates
concers. reduces logic
2018-01-02 23:38:01 +05:30

22 lines
693 B
JavaScript

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$;
};