Discovered login bug and (tentative) fix

221 views
Skip to first unread message

Justin Lacy

unread,
Jul 13, 2013, 9:31:03 AM7/13/13
to facebook-act...@googlegroups.com

I have seen many other people with a similar error - if the user is not already logged in and they go through the Facebook.init() -> Facebook.login() sequence, the login will fail every time.

The problem is if you call Facebook.login() from the Facebook.init() callback function, a bug in Facebook.handleAuthResponseChange()
will cause Facebook to call _loginCallback in the listener for init.

Here is the offending code:

<code>
if (_initCallback != null) {
    _initCallback( authResponse, null );
    _initCallback = null;
}
        
if (_loginCallback != null) {
            _loginCallback( authResponse, null );
          _loginCallback = null;
 }
</code>

As you can see, if the _initCallback() calls Facebook.login(), the _loginCallback gets set to a non-null value and will return instantly
in the very next if-block.

Solution is to save the versions of the callbacks BEFORE calling the callbacks. It's still a delicate situation and I haven't thought
through all the ramifications yet, but the basic fix works like this:

<code>
var tempInit:Function = _initCallback;
var tempLogin:Function = _loginCallback;

if (_initCallback != null) {

    _initCallback = null;
    tempInit( authResponse, null );
          
}
        
if ( tempLogin != null ) {

     _loginCallback = null;
     tempLogin( authResponse, null );

}
</code>


In fact any time you have a situation where a callback is triggered, the callback should be stored locally and cleared BEFORE calling the callback - because the callback function might set a new callback:

NOT:

callback();
callback = null;

BUT:

var temp:Function = callback;
callback = null;
temp();

Reply all
Reply to author
Forward
0 new messages