5

I'm using passport.js in a node.js app to get OAuth working (awesome!), but now, I'm having problem with one thing.

I'm using backbone.js on client side, to create the views (I'm trying to create a SinglePage app...), and the only way I'm thinking about getting user id or something like that in backbone is creating first an input-hidden in jade templates and then passing it to the constructor in my backbone views.... or just assign the value to a javascript variable and passing it to the router that manages all the views, and pass it to every view that need it

I think it's not a good idea, and there might be better options!

How would you do it?

Thanks!

laggingreflex
  • 32,948
  • 35
  • 141
  • 196
Javier Manzano
  • 4,761
  • 16
  • 56
  • 86

1 Answers1

0

I haven't done anything in Backbone yet, but there are solutions here, here and here already. As long as you get the session id somewhere, you can retrieve the session with the cookie-package (cookie has been outsourced from connect-utils):

if(handshakeData.headers.cookie) {
  c = cookie.parse(handshakeData.headers.cookie);
  sid = connect.utils.parseSignedCookie(c['connect.sid'], 'keyboard cat');
  redis.get('sess:'+sid, function(error, result) {
    session = JSON.parse(result);
    handshakeData.uid = session.passport.user;
    callback(null, true);
  });
Community
  • 1
  • 1
Patrick
  • 7,903
  • 11
  • 52
  • 87