Sunday, 6 March 2016

connect-redis for redisStore on heroku + passport?

dear r/node,I'm having a dog of a time getting connect-redis to work as the basis for redisStore with passport on heroku. specifically, the system works just fine on my local machine, and i have checked that the logged in user is serialized properly, deserialized properly, that the local redis db gets passed the correct info, and that the cookie is set properly.however, on heroku, req.user is undefined.i suspect this is because i am not connecting to redis on heroku properly. i am working with:var express = require('express'); var ejs = require('ejs'); var app = express(); var bodyParser = require('body-parser'); var cookieParser = require('cookie-parser'); var session = require('express-session'); var passport = require('passport'); var RedisStore = require('connect-redis')(session); var LocalStrategy = require('passport-local').Strategy; var flash = require('connect-flash'); app.set ('view engine', 'ejs'); app.use(express.static(__dirname + '/public')); app.set('port', (process.env.PORT || 5000)); var pg = require('pg'); var connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/lederdev'; var redisUrl = process.env.REDISTOGO_URL || 'redis://127.0.0.1:6379'; app.use(cookieParser()); app.use(bodyParser.urlencoded({extended: true})); app.use(session({ store: new RedisStore({url: redisUrl}), secret: 'february2016', maxAge: 3600000, resave: true, saveUninitialized: true, cookie: { path: '/', maxAge: 1000*60*60*24*30*12 } })); app.use(passport.initialize()); app.use(passport.session()); app.use(flash()); I know I enter maxage above twice, but I don't think that is the issue - if so, please let me know. frankly, at this point, the "cookie" preferences entered into the session call was a desperate attempt by me - just throwing stuff to see if it sticks - to see if somehow heroku was super picky about how it sets cookies.anyway, any insight would be super appreciated!!thanks very much, dotcomrades.

Submitted March 07, 2016 at 04:37AM by lawstudent2

No comments:

Post a Comment