1

My code used to work, and after a few days of not touching it because cloud9ide wasn't working properly, it stopped working. I always get a req.loggedin as undefined with everyauth module. I do a simple :

app.get('/view/:htmlpage', function(req, res){
        console.log(req);
        if(req.loggedIn) {
          res.sendfile('./views/' + req.params.htmlpage + '.html');
        }
        else{

          res.send('You need to be authenticated with a <a href="www.facebook.com">Facebook</a>');

        }
    });

The req prints:

{ sessions:

 // IGNORE ALL KIND OF STUFF //

 "loggedIn":true,"userId":"4ec448e67a06792a32000006"}}' },
 hash: [Function],
 generate: [Function] },

What is wrong? everything seems find, but I still get undefined...???

Here is a bigger extract of the req:

 sessionStore:
   { sessions:
      { 'OoYpzK3P9V5EuVzsaIzcENKA.u86589nxU+3B5y/DZ/GUWmLLd4hKiVMZQlM3uXpkpdk': '{"lastAccess":1321711710418,"cookie":{"originalMaxAge":14400000,"expires":"2011-11-19T18:08:30.421Z","httpOnly":true,"path":"/"}}',
        'ro6CtsS269MqF9DhXHIYVzfi.VVqZHKF6DcGewMbS+myRWbeev6oMmJZEqWQ6oq0Y2mE': '{"lastAccess":1321711711837,"cookie":{"originalMaxAge":14400000,"expires":"2011-11-19T18:08:31.838Z","httpOnly":true,"path":"/"}}',
        'AjXcalemAKkn534BBNDd1ouq.rl/JpdRKMMDoIuEj2IwEe77oesx5ZghAK4fInJT44ZQ': '{"lastAccess":1321711712927,"cookie":{"originalMaxAge":14400000,"expires":"2011-11-19T18:08:33.839Z","httpOnly":true,"path":"/"},"auth":{"facebook":{"user":{"id":"x","name":"x x","first_name":"x","last_name":"x","link":"http://www.facebook.com/x","username":"x","location":{"id":"x","name":"x, Ontario"},"education":[{"school":{"id":"x","name":"x"},"year":{"id":"x9","name":"2005"},"type":"High School"},{"school":{"id":"x","name":"x"},"year":{"id":"x","name":"2010"},"concentration":[{"id":"x","name":"x"}],"type":"x"}],"gender":"male","email":"x","timezone":-5,"locale":"fr_CA","verified":true,"updated_time":"2011-11-16T13:38:18+0000"},"accessToken":"AAAD8xT5k5w8BAIbAjZBe0z20idA2qSFIxBJXyQUVqHK0yDCSjYiyZCbtahwup8lpNN8ijWwVhJy5ZAPdwsb8IQoL2EUBq8FVtREjrY3V2gkhQObdC4u"},"loggedIn":true,"userId":"4ec448e66a06792c32000006"}}' },
     hash: [Function],
     generate: [Function] },
  sessionID: 'SwW3fTOcQYCsJ7bRPJI3DsK4.YUolspdQE6fgM4gE/o6HNQfDrX+o94aTfgd4G8Hgv1k',
  session:
   { lastAccess: 1321711713901,
     cookie:
      { path: '/',
        httpOnly: true,
        _expires: Sat, 19 Nov 2011 18:08:33 GMT,
        originalMaxAge: 14400000 } },
  logout: [Function],
  _route_index: 1,
guiomie
  • 4,988
  • 6
  • 37
  • 67
  • Do you get an error message? What is it if you do? – EhevuTov Nov 17 '11 at 01:29
  • No error message, its just impossible to see an instantiated loggedIn. – guiomie Nov 19 '11 at 03:43
  • 1
    just curious guiomie - did you ever figure this out? i'm just starting to use everyauth right now, and i can't figure out how to check for somebody being logged in (like what you're doing) since none of the documented methods seem to work... – thisissami Jun 12 '12 at 21:08
  • I created a function that refers to req.session.auth.facebook.user.id, and this gives me the users Id. This way, it is always working, everyauth broken or not. Also, console.log(req.session) and from there extract whatever extra information you want to use. – guiomie Jun 14 '12 at 02:12

1 Answers1

3

Use

if(req.session.loggedIn)

instead.

The session is a part of the req object.

staackuser2
  • 12,172
  • 4
  • 42
  • 40
  • This still pulls an undefined. req.loggedIn used to work properly before. Not sure if I updated my everyauth module, and this functionnality is deprecated... – guiomie Nov 17 '11 at 20:57
  • I see in your question that it says ```sessions```. That seems to be non-standard, but you can try ```req.sessions.loggedIn``` then. If you can see it in the console.log output, you can access it if you use the right names. – staackuser2 Nov 18 '11 at 02:24
  • sessions is actually part of a bigger object with more properties. So their must be an elegant way of getting this again. – guiomie Nov 19 '11 at 03:16