Re: Newbie question here

71 views
Skip to first unread message

mscdex

unread,
May 22, 2013, 8:25:54 AM5/22/13
to nodejs
On May 22, 1:19 am, Toddy Mladenov <m...@toddysm.com> wrote:
> It seems the session object is not created but I have no idea why.
> Shouldn't this be created automatically when the user accesses the site?

Are you sure that the session middleware is being loaded before the
code in question?

Toddy Mladenov

unread,
May 23, 2013, 11:35:19 AM5/23/13
to nod...@googlegroups.com
I am not. Can you give me some hints what this session middleware should be?

mscdex

unread,
May 23, 2013, 12:03:32 PM5/23/13
to nodejs
On May 23, 11:35 am, Toddy Mladenov <m...@toddysm.com> wrote:
> I am not. Can you give me some hints what this session middleware should be?

Just look at the order of your `app.use()` calls.

According to passport's site, the order should be something like this:

app.configure(function() {
app.use(express.static('public'));
app.use(express.cookieParser()); // first
app.use(express.bodyParser());
app.use(express.session({ secret: 'keyboard cat' })); // second
app.use(passport.initialize()); // third
app.use(passport.session()); // fourth
app.use(app.router); // fifth
});
Message has been deleted

Toddy Mladenov

unread,
May 27, 2013, 1:07:01 PM5/27/13
to nod...@googlegroups.com
Well, all of those are done but the session object is still undefined after I login with Twitter (Twitter strategy is used). I don't see any cookie except the express.sid one that is set for the site. Shouldn't there be passport cookie too? Also, is the session object global and accessible from everywhere?

Thanks 

On Tuesday, May 21, 2013 10:19:29 PM UTC-7, Toddy Mladenov wrote:
Just started looking as some node.js code that I inherited. It uses passport and express and I get the following error when I try to load the home page of the site:

Tue May 21 2013 22:12:38 GMT-0700 (PDT) 1
GET / controller: main action: index
>>> perform protect from forgery
<<< protect from forgery [0 ms]
>>> perform loadUser

/Users/toddysm/Development/Projects/iddioodev/app/controllers/application_controller.js:19
if (session.passport.user) {
          ^
TypeError: Cannot read property 'passport' of undefined
    at Object.loadUser (/Users/toddysm/Development/Projects/iddioodev/app/controllers/application_controller.js:19:13)
    at Object.<anonymous> (/Users/toddysm/Development/Projects/iddioodev/node_modules/railway/lib/controller.js:377:20)
    at /Users/toddysm/Development/Projects/iddioodev/node_modules/railway/lib/controller.js:354:24
    at process._tickCallback (node.js:415:13)

It seems the session object is not created but I have no idea why. Shouldn't this be created automatically when the user accesses the site?

Thanks for the help!
Toddy
Reply all
Reply to author
Forward
0 new messages