My application is using express for managing sessions and passport.js for authentication (stored in Mongodb). When a user logins in, I want to check if that user already has a living session. I want to use run-middleware to programmatically query mongodb for all the live sessions.
'use strict';
import path from 'path';
import passport from 'passport';
import {Strategy as LocalStrategy} from 'passport-local';
import express from 'express';
import session from 'express-session';
import _ from 'lodash';
import Session from '../../api/session/session.model';
var app = express();
require('run-middleware')(app);
function localAuthenticate(User, email, password, done, req) {
User.findOne({
email: email.toLowerCase()
}).exec()
.then(user => {
if (!user) {
return done(null, false, {
message: 'This email is not registered.'
});
}
// HERE is where I am trying to use the runMiddleware
app.runMiddleware('/sessions',{},function(code,data){
console.log(code) // 200
console.log(data) // { user: '20', name: 'Moyshale' }
});
user.authenticate(password, function(authError, authenticated) {
if (authError) {
return done(authError);
}
if (!authenticated) {
return done(null, false, { message: 'This password is not correct.' });
} else {
return done(null, user);
}
});
})
.catch(err => done(err));
}
export function setup(User, config) {
passport.use(new LocalStrategy({
passReqToCallback: true,
usernameField: 'email',
passwordField: 'password' // this is the virtual field on the model
}, function(req, email, password, done) {
return localAuthenticate(User, email, password, done, req);
}));
}
if (state.pipesCount === 0)
^
TypeError: Cannot read property 'pipesCount' of undefined
at IncomingMessage.Readable.unpipe (_stream_readable.js:634:12)
at unpipe (/home/enview/node_modules/unpipe/index.js:47:12)
at send (/home/enview/node_modules/finalhandler/index.js:184:3)
at Immediate.<anonymous> (/home/enview/node_modules/finalhandler/index.js:113:5)
at Immediate.<anonymous> (/home/enview/node_modules/express/lib/router/index.js:618:15)
at runCallback (timers.js:568:20)
at tryOnImmediate (timers.js:546:5)
at processImmediate [as _immediateCallback] (timers.js:525:5)
I am trying to use run-middleware within an angular-fullstack application.
My application is using express for managing sessions and passport.js for authentication (stored in Mongodb). When a user logins in, I want to check if that user already has a living session. I want to use run-middleware to programmatically query mongodb for all the live sessions.
The error I am getting is: