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 9008213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:53:23+00:00 2026-06-16T01:53:23+00:00

I’m having trouble getting sessions with mongodb to work properly. I’ve setup the following

  • 0

I’m having trouble getting sessions with mongodb to work properly. I’ve setup the following code which, without a problem, creates the user.

I can also see my sessions database being populated which looks like this:


(source: wes.io)

Problem is, I am never at a logged in state. It works fine if I just use memory to store the session, but when moving to mongodb, it doesn’t work. Here is where I think the problem code is, but you can see the entire app here: http://wes.io/LNVg

passport.use(new LocalStrategy(
  function(username, password, done) {
    console.log('Trying to log in as '.green, username);
    
    User.findOne({ name: username }, function(err, user) {
      if (err) {return done(err); }

      if(user) {
        console.log('Found user with the username of'.green,user); 
        done(null, user);
      } 

      else {
        console.log('No user found...  '.red.inverse, username, password);
        var user = new User();
        user.name = username;
        user.username = username;
        user.password = password;
        user.save(function(err){
          if(err) { throw err; }
          console.log('User created and saved'.green, user)
          done(null, user);
        })
      };

    });
  }
));

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

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

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  app.use(require('less-middleware')({ src: __dirname + '/public' }));
  app.use(express.favicon());
  app.use(express.bodyParser());
  app.use(express.logger('dev'));
  app.use(express.methodOverride());
  app.use(express.session({ 
        store: store
      , secret: 'applecake'
      , cookie : {
            maxAge : 604800 // one week
        }
  }));
  app.use(passport.initialize());
  app.use(passport.session()); 
  app.use(app.router);
});

Edit: here is the code for the session store:

var express = require('express')
  , colors = require('colors')
  , routes = require('./routes')
  , mongoose = require('mongoose')
  , SessionStore = require("session-mongoose")(express)
  , store = new SessionStore({
        url: "mongodb://localhost/fb-session",
        interval: 120000 // expiration check worker run interval in millisec (default: 60000)
    })
  , Schema = mongoose.Schema
  , flash = require('connect-flash')
  , userz = require('./routes/user')
  , http = require('http')
  , path = require('path')
  , passport = require('passport')
  , LocalStrategy = require('passport-local').Strategy;
  • 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-16T01:53:24+00:00Added an answer on June 16, 2026 at 1:53 am

    Turns out it was an issue with the serialize and deserialze methods. Here is my example with the name although it will be changed to a user ID

    passport.serializeUser(function(user, done) {
        done(null, user.name);
    });
    passport.deserializeUser(function(name, done) {
        done(null, { name: name });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.