passport.js - Passport: session serialization failed with serialization functions present -
i'm adding authentication node app using `feathers-passport following configuration:
.configure(featherspassport({ secret: 'some-secret', store: new mongostore({db: 'demo-session'}), resave: false, saveuninitialized: false }))
and configure passport:
var localoptions = { usernamefield: 'email', passwordfield: 'password' }; passport.serializeuser(function(user, done) { done(null, user._id); }); passport.deserializeuser(function(id, done) { api.service('users').get(id, {}, done); }); passport .use(new localstrategy(localoptions, function(email, password, done){ api.service('users').authenticatelocal(email, password, done); }))
to authenticate, have route setup:
.post('/users/authenticate', function(request, response, next){ passport.authenticate('local', function(error, user){ //error comes null , user valid object request.login(user, function(error){ if(error) return next(error); if(!user) return next(new error("no user found")); else { var token = tokenissue({id: user.id}); response.status(201).json({token: token, id: user.id}); } }); })(request, response, next); })
however, session serialization fails standard error: failed serialize user session
, indicate serializeuser
, deserializeuser
functions aren't present. except in case are. went through passport source , here (line 265 of authenticator.js
):
var stack = this._serializers; (function pass(i, err, obj) { // serializers use 'pass' error skip processing if ('pass' === err) { err = undefined; } // error or serialized object obtained, done if (err || obj || obj === 0) { return done(err, obj); } var layer = stack[i]; if (!layer) { return done(new error('failed serialize user session')); }
this._serializers
prints out []
when var layer = stack[i]
called, check if(!layer)
passes , error thrown. seem passport isn't picking i've defined serialization functions , i'm unsure if that's result of passport or consequence of using feathers-passport
. followed feathers-passport
guide closely , can't figure out going wrong. appreciated.
Comments
Post a Comment