Mongoose-Auth/Express/Connect Not holding onto session issue

Im currently working on a node js app which i am trying to create a user authentication process using Monggose-Auth. I have followed through on multiple tutorials examples and all the guides i could find on how to use Mongoose-Auth however i have hit a wall.

My basic password auth seems to work and redirects to the correct places and holds onto the user etc etc. My problem is that on adding my requires login function to a user profile page i have an issue in that i am simply redirected back to the login page. It seems that this is because the session is somehow lost however when i look at my everyauth debug output (mongoose-auth is built on top of everyauth) I see the following

starting step - displayLogin

...finished step

GET /favicon.ico

starting step - extractLoginPassword

...finished step

starting step - authenticate

...finished step

starting step - interpretUserOrErrors

...finished step

starting step - getSession

...finished step

starting step - addToSession

...finished step

starting step - respondToLoginSucceed

...finished step

starting step - respondToLoginFail

...finished step

GET /users/profile

starting step - displayLogin

...finished step

GET /favicon.ico

My app can be found here --> https://github.com/Themitchell/Node-Express-Connect-Mongoose-Auth-Stack <-- and should be quick to set up if you would like to see for yourself! It uses the correct package.json etc so just run

npm install then node server.js

I thought about pulling an example from elsewhere to try and build upon but i would like to understand what the issue is rather than hack on top of something i dont understand yet!

As far as i am aware mongoose-auth should not persist the session itself but instead I would have to do this via connect for example which i thought i was doing correctly.

The files to look at in the project are likely in

config/environment.js

app/models/user.js

and finally

config/routes.js has the requiresLogin function (i know its only here for now.

Thanks for your help in advance folks :)

This is not a full answer but you can see how I manage to deal with Auth in my project. I used Mongoose, Express, Passport + Passport Local to deal with Auth and connect-mongodb to persist sessions (was quiet hard to get the full stack working). The advantage is that sessions are retrieved even between server restarts.

Link to the main files :

What's important :

  • Auth.js will help you A LOT to adapt Passport Auth with your Mongoose.
  • Setting connect-db to persist sessions isn't easy ut it's very comfortable.

Take a look at how I setup connect-db (best seen is LoastAndFound.js , or .coffee) :

app.use(express.session({
    secret: 'awesome unicorns',
    maxAge: new Date(Date.now() + 3600000),
    store: new common.mongoStore({
        db: Data.mongoose.connection.db
    }, function(err) {
        return console.log(err || 'connect-mongodb setup ok');
    })
 }));

Note : Please forgive me for my code not being perfect, needing more comments and not being tested.