Note that there are some explanatory texts on larger screens.

plurals
  1. PONode.js + express.js + passport.js : stay authenticated between server restart
    primarykey
    data
    text
    <p>I use passport.js to handle auth on my nodejs + express.js application. I setup a LocalStrategy to take users from mongodb</p> <p>My problems is that <strong>users have to re-authenticate when I restart my node server</strong>. This is a problem as I am actively developing it and don't wan't to login at every restart... (+ I use node supervisor)</p> <p>Here is my app setup :</p> <pre><code>app.configure(function(){ app.use('/static', express.static(__dirname + '/static')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser()); app.use(express.session({secret:'something'})); app.use(passport.initialize()); app.use(passport.session()); app.use(app.router); }); </code></pre> <p>And session serializing setup :</p> <pre><code>passport.serializeUser(function(user, done) { done(null, user.email); }); passport.deserializeUser(function(email, done) { User.findOne({email:email}, function(err, user) { done(err, user); }); }); </code></pre> <p>I tried the solution given on a blog (removed the link as it does not exist any more) using connect-mongodb without success</p> <pre><code>app.use(express.session({ secret:'something else', cookie: {maxAge: 60000 * 60 * 24 * 30}, // 30 days store: MongoDBStore({ db: mongoose.connection.db }) })); </code></pre> <p><strong>EDIT</strong> additional problem : only one connection should be made (use of one connexion limited mongohq free service)</p> <p><strong>EDIT 2</strong> solution (as an edition as I my reputation is to low to answer my question by now</p> <p>Here is the solution I finally found, using mongoose initiated connection</p> <pre><code>app.use(express.session({ secret:'awesome unicorns', maxAge: new Date(Date.now() + 3600000), store: new MongoStore( {db:mongoose.connection.db}, function(err){ console.log(err || 'connect-mongodb setup ok'); }) })); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload