Session changes not persistent

56 views
Skip to first unread message

Ben Corne

unread,
Jun 30, 2012, 7:32:47 PM6/30/12
to no...@googlegroups.com
Hi. I'm experimenting with now.js, and sure like the idea.

However I've ran into trouble with session support using express.

This is my program's cflow:

clientside: user visits website
clientside: user clicks guest login
clientside: guest login click triggers now.guestLogin()
serverside: guestLogin creates a new guest user, and finishes login with finishLogin
serverside: finishLogin assigns the newly created guest user object to session.user
serverside: finishLogin triggers client's now.loginOk() method
clientside: loginOk is called and a request to a page requiring session.user is a user.

however the session.user set in finishLogin seems not to be persisted. So I went digging, logging the session variable when setting it and when requesting the page requiring to be logged in.

Server console:
$ node app.js
Express server listening on port 80 in development mode
now method session after user assignment =
{ lastAccess: 1341098607952,
  cookie:
   { path: '/',
     httpOnly: true,
     _expires: Sun, 01 Jul 2012 03:23:27 GMT,
     originalMaxAge: 14400000 },
  user: { guest: true, nickname: 'guest0' } }
express session output =
{ lastAccess: 1341098609861,
  cookie:
   { path: '/',
     httpOnly: true,
     _expires: Sun, 01 Jul 2012 03:23:27 GMT,
     originalMaxAge: 14400000 } }

As you can see, the session does contain an actual user after assigning session.user (now method session output)
but it disappears again when I request a page after this (express session output).

Any ideas what's wrong here?

Kind regards
Ben

Ben Corne

unread,
Jul 1, 2012, 6:14:42 AM7/1/12
to no...@googlegroups.com
Been looking for the source of the problem a bit more and stumbled on the v0.8 update on the site:

Experimental connect/express session support. Simply pass a connect or express http server in nowjs.initialize and this.user.session should be available. Change options cookieKey to specificy connect.sid key 

Perhaps this is something I forgot, specifying the connect.sid. No idea how to do this though. I've tried initializing nowjs asfollows:
nowjs.initialize(app,{cookieKey: sessionSecret}); but then my session object is undefined, which is kind of worse than before.

Ben Corne

unread,
Jul 1, 2012, 7:12:40 AM7/1/12
to no...@googlegroups.com
I've produced a smaller example express app to reproduce the problem.

The cflow:
client fills in name, hits send.
now.login(nickname) is triggered.
server sets this.user.session.nickname to nickname
server tells client login succeeded.
client does GET '/'.

server console output:
$ node app.js
Express server listening on port 3000 in development mode
normal request's session:
{ lastAccess: 1341140771278,
  cookie:
   { path: '/',
     httpOnly: true,
     _expires: Sun, 01 Jul 2012 15:06:11 GMT,
     originalMaxAge: 14400000 } }
now method session after assingment
{ lastAccess: 1341140772089,
  cookie:
   { path: '/',
     httpOnly: true,
     _expires: Sun, 01 Jul 2012 15:06:12 GMT,
     originalMaxAge: 14400000 },
  nickname: 'Ben' }
normal request's session:
{ lastAccess: 1341140774219,
  cookie:
   { path: '/',
     httpOnly: true,
     _expires: Sun, 01 Jul 2012 15:06:12 GMT,
     originalMaxAge: 14400000 } }

The source for the express app, incase you want to test yourself or verify I've done all that should have been done.
don't forget to do npm install to install nowjs & other dependencies.

Kind regards
Ben

On Sunday, July 1, 2012 1:32:47 AM UTC+2, Ben Corne wrote:

Ian Serlin

unread,
Jul 1, 2012, 5:31:38 PM7/1/12
to no...@googlegroups.com
Hey Ben,

It looks like session support is busted and I don't think it's going to be updated anytime soon. I'll take a more in-depth look later.

Ben Corne

unread,
Jul 1, 2012, 6:13:36 PM7/1/12
to no...@googlegroups.com
Hi Ian,

For my experiment it's fine to use the now#User object, so I'll manage.
Any page requesting authentication, I've changed so it gets served via now.js, but it is not ideal.

I'd very much like to use now.js for future projects where I think session support is crucial to have a good integration with the highly interactive part of the website using now.js and the rest of the website.

I'll keep an eye out on the mailing list :)

Cya, thanks for the reply.


On Sunday, July 1, 2012 1:32:47 AM UTC+2, Ben Corne wrote:
Reply all
Reply to author
Forward
0 new messages