having some bind problems

11 views
Skip to first unread message

bryan rasmussen

unread,
Nov 18, 2014, 6:01:01 AM11/18/14
to compo...@googlegroups.com
Hi,

I have the following

before('pass', function() {
    if (!session.passport.user) {
         next();
    } else {
        if(session.LoggedInUser){
            this.blah = "BLAH!";
            next();
        }else{
            User.find(session.passport.user, function(err, user) {
                if (user && user.approved) {
                    session.LoggedInUser = user;
                    req.user = user;
                    this.loggedInUser = user;
                   
                    }
                next();
            });
        }
   

}}.bind(this));

before('auth', function() {
    console.log(this.blah);
   // other stuff happens here, but nothing that undefines this.blah;
}.bind(this));

auth comes after pass, since my session.LoggedInUser is set when I do my console.log it says BLAH!



then in another controller I
load('application');

and

action(function index() {
    layout("application");
    console.log(this.blah);
});


when I do the console.log on this.blah is says undefined.

Why?

If I have a bind on my User.find inside of pass then I can bind what I want and pass it along, as long as I call that User.find.

I had expected I could just move the bind out to the outer function but that doesn't work.

What do I have to do inside of the part of pass that says

if(session.LoggedInUser){
            this.blah = "BLAH!";
            next();
        }

in order to bind blah?

Thanks,
Bryan Rasmussen
Reply all
Reply to author
Forward
0 new messages