jaredhanson / jaredhanson/passport

Error: Failed to serialize user into session. Possible lack of support for redis session store?

Open
#331 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
23.5k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I'm using a redis session store and I'm combining both FacebookStrategy and LocalStrategy (I hope I can?). I have passport setup like this:

```
var express = require('express')();
var router = express.Router();
router.use(passport.initialize());
router.use(passport.session());

var redisSessionStore = redisClient.redisSessionStore;
P.promisifyAll(redisClient.redisSessionStore);

var sess = {
store: redisSessionStore,
secret: 'secret',
cookie: {
expires: false,
}
}

express.use(session(sess));

module.exports = passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackUrl: config.facebook.callbackUrl
},
function(accessToken, refreshToken, profile, done) {
// validate user existence or create new one.
process.nextTick(function () {
console.log(accessToken);
console.log(profile);
return done(null, profile);
});
}
));
module.exports = passport.use(new LocalStrategy(
function(username, password, done) {
console.log('authenticating: ' + username);
var user = {
_id: 1,
username: 'mari',
password: 'alako'
};
return done(null, user);
}
));

passport.serializeUser(function(user, done) {
console.log('serializeUser: ' + user._id)
done(null, user._id);
});
passport.deserializeUser(function(id, done) {
var user = {
_id: 1,
username: 'mari',
password: 'alako'
};
done(null, user);
});

// login route with passport
router.post('/userlogin', bodyParser.text({ type: 'urlencoded' }), function(req, res, next) {
passport.authenticate('local', function(err, user, info) {
console.log('Retrieved User is: ' + JSON.stringify(user));
req.logIn(user, function(err){
if (err) { return next(err); }
console.log('passport: ' + user.username + ' is logged in ');
});
})(req, res, next);
res.send('authenticating with passport');
});
```

Contributor guide

Open the contributing guide

Research direction

The issue names no repository files or tests; begin with the middleware, Redis session configuration, and serializeUser usage shown in the report. Reproduce the local login flow with the Redis store and both strategies, then trace the serialization error. Done means the reported login succeeds without the session serialization failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js, redis
Domain
authentication, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.