1

everyauth.everymodule.findUserById is called with an id parameter that everyauth picks up from req.session. This then can be used to load the user info which is passed into req.user

On localhost when the node app.js server is restarted the session is cleared.

What I'd like to do is to set a cookie which contains the user id that I can than pass to everyauth so that on server restart it knows the id and everymodule.findUserBy Id can do its thing.

I'm using expressjs and have found that both connect-mongodb and cookie-sessions don't work. So what would the suggested way of approaching this be?

In other words is there a way of pre-populating everyauth with user info?

molicule
  • 5,481
  • 3
  • 29
  • 40

1 Answers1

3

I think you need to setup a persistent session store outside of expressjs. Because sessions by default in expressjs are kept in-memory, they are lost when you restart the server. I ended up going with connect-redis over connect-mongo, even though am using MongoDb for my database. I wanted the session data to be kept separate from the database. I'm not sure if it was necessary, but it was super simple to setup.

Also, while we are on the topic, here are a few of the other hurdles that I ran into with sessions:

  • Make sure that the server time is set correctly, or the sessions could expire prematurely.
  • The one thing that caught me during development was a result of the fact that the session is fingerprinted by the user agent string provided by the browser. I found out that I had a plugin enabled on firefox ( FirePHP, a Firebug extension ) that was modifying my User Agent string after the first request. This was causing the sessions to act like they were only valid until the browser was closed. It took me a few days to track that down.

Hope this helps.

jhoff
  • 716
  • 7
  • 14