2

I am creating node.js app using express, everyauth and now.js.

I have a server-side now.js function in which I want to be able access the 'User' object for the authenticated user calling this function. I dont have access to the a 'request' or 'session' object, I only have the user cookie and connect.sid

My question is, whats best way to get the session information I'm looking for? Do I store these details in the cookie when the original page request comes in? Or Is there a way to get the session object from the connect.sid?

Thanks

jsalonen
  • 29,593
  • 15
  • 91
  • 109
gonzohunter
  • 832
  • 1
  • 8
  • 18

1 Answers1

2

To solve this I created a Memory Session store, which I passed in when creating the Express App. Which allows me to access the session store

When a server-side nowjs function is called I use the connect.sid to retrieve the users session from the session store. This session then has all the authenticated users details.

gonzohunter
  • 832
  • 1
  • 8
  • 18
  • 2
    Little bit more detail? Struggling with the same issue, using a Redis store. How do I get the session from that? Thanks – Patrick Nov 24 '11 at 10:05
  • I wonder what is the use of a memory store if we can directly assign variables to `now` object. For example at client-side `now.User.name='Mr. Bentle`. Shouldn't this info be available at server-side (when Mr. Bentle makes a request to server) in `this.now.User.name`? – Juzer Ali Mar 30 '12 at 10:28
  • @juzerali - The user might modify his client to set now.User.name = 'whatever he wants'. It is better to do this server-side using sessions to avoid user shenanigans. – Legendre Sep 23 '12 at 17:51