Passport.js: access to the user when using the trunk

I am using passport.js in a node.js application to get OAuth to work (awesome!), But now I have a problem with something.

I use backbone.js on the client side to create views (I'm trying to create a SinglePage application ...), and the only way I'm going to get a user ID or something like that backbone creates a hidden entry in jade templates first, and then passes it to the constructor in my views on highways .... or just assigns a value to the javascript variable and passes it to the router, which manages all the views, and passes it to all kinds that need it

I think this is not a good idea, and there might be better options!

How do you do this?

Thank!

+5
source share
1 answer

I haven't done anything in Backbone yet, but there are solutions here , here and here . As long as you get the session ID somewhere, you can get the session with cookie -package (the cookie was outsourced from the connect-Utils application):

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);
  });
0
source

All Articles