Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:39:01+00:00 2026-06-01T22:39:01+00:00

I use passport.js to handle auth on my nodejs + express.js application. I setup

  • 0

I use passport.js to handle auth on my nodejs + express.js application. I setup a LocalStrategy to take users from mongodb

My problems is that users have to re-authenticate when I restart my node server. This is a problem as I am actively developing it and don’t wan’t to login at every restart… (+ I use node supervisor)

Here is my app setup :

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);
});

And session serializing setup :

passport.serializeUser(function(user, done) {
    done(null, user.email);
});

passport.deserializeUser(function(email, done) {
    User.findOne({email:email}, function(err, user) {
        done(err, user);
    });
});

I tried the solution given on a blog (removed the link as it does not exist any more) using connect-mongodb without success

app.use(express.session({
    secret:'something else',
    cookie: {maxAge: 60000 * 60 * 24 * 30}, // 30 days
        store: MongoDBStore({
        db: mongoose.connection.db
    })
}));

EDIT additional problem : only one connection should be made (use of one connexion limited mongohq free service)

EDIT 2 solution (as an edition as I my reputation is to low to answer my question by now

Here is the solution I finally found, using mongoose initiated connection

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');
        })
}));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:39:03+00:00Added an answer on June 1, 2026 at 10:39 pm

    There’s an opensource called connect-mongo that does exactly what you need – persists the session data in mongodb

    usage example (with a reuse of mongoose opened connection) :

    var session = require('express-session');
    var MongoStore = require('connect-mongo')(session);
    var mongoose = require('mongoose');
    mongoose.connect('mongodb://localhost/sess');
    app.use(express.session({
        secret:'secret',
        maxAge: new Date(Date.now() + 3600000),
        store: new MongoStore(
        // Following lines of code doesn't work
        // with the connect-mongo version 1.2.1(2016-06-20).
        //    {db:mongoose.connection.db},
        //    function(err){
        //        console.log(err || 'connect-mongodb setup ok');
        //   }
        {mongooseConnection:mongoose.connection}
        )        
    }));
    

    you can read more about it here: https://github.com/kcbanner/connect-mongo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an Air application which uses sockets. I need to connect to nexus.passport.com:443
I have this code, $sqlstr = mysql_query( SELECT * FROM sales where passport =
Alright, so here's the dealio: I'm working on a Ruby app that'll take data
Use Eclipse Classic with ADT plugin. Tried to make project from existing example of
I've successfully implemented passport-local into my Express/Mongoose web-app but I'm having trouble figuring out
use case example I have a servlet that is receiving login requests. If a
Use MongoDB GridFS store images and images stored directly on disk What are the
Use case: 3rd party application wants to programatically monitor a text file being generated
use qcvalues_test go select [finalConc] ,[rowid] from qvalues where rowid in (select rowid from
when to use windows authentication, form authentication, passport authentication, none? I don't find on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.