node.js - Nodejs passport authentication hanging -
node.js - Nodejs passport authentication hanging -
i'm next nodejs book here: https://www.packtpub.com/web-development/mean-web-development
all going smoothly until seek , log in using passport module. hangs no errors. have tried other solutions i've found on such re-ordering middleware, think might different versions of express, of syntax looks different (and doesn't work). here relevant parts. help appreciated!
package.json:
{ "name": "mean", "version": "0.0.3", "description": "first mean app", "dependencies": { "express": "~4.8.8", "morgan": "~1.3.0", "compression": "~1.0.11", "body-parser": "~1.8.0", "method-override": "~2.2.0", "express-session": "~1.7.6", "ejs": "~1.0.0", "connect-flash": "~0.1.1", "mongoose": "~3.8.15", "passport": "~0.2.1", "passport-local": "~1.0.0" } }
express.js:
module.exports = function(){ var app = express(); if(process.env.node_env === 'development'){ app.use(morgan('dev')); }else if(process.env.node_env === 'production'){ app.use(compress()); } app.use(bodyparser.urlencoded({ extended: true })); app.use(bodyparser.json()); app.use(methodoverride()); app.use(session({ saveunitialized: true, resave: true, secret: config.sessionsecret })); app.set('views', './app/views'); app.set('view engine', 'ejs'); app.use(flash()); app.use(passport.initialize()); app.use(passport.session()); require('../app/routes/index.server.routes.js')(app); require('../app/routes/users.server.routes.js')(app); app.use(express.static('./public')); homecoming app; };
passport.js
module.exports = function(){ var user = mongoose.model('user'); passport.serializeuser(function(user, done){ done(null, user.id); }); passport.deserializeuser(function(id, done){ user.findone({ _id: id }, '-password -salt'), function(err, user){ done(err, user); }; }); require('./strategies/local.js')(); };
the routing:
app.route('/signin') .get(users.rendersignin) .post(passport.authenticate('local',{ successredirect: '/', failureredirect: '/signin', failureflash: true }));
edit: seems passport.deserializeuser function things break
well i've gone passport docs, , pasted in code there, , seems work. so... thought why mean book illustration isn't working?
code worked:
passport.deserializeuser(function(id, done) { user.findbyid(id, function(err, user) { done(err, user); }); });
node.js passport.js
Comments
Post a Comment