I have a site that uses the Facebook JavaScript API to allow users to log in to a Ruby on Rails application through Facebook. When a user clicks to log in or log out, Facebook code does the authentication and then raises an event and supplies a cookie with authentication parameters. The cookie is sent to my server, and I use it to authenticate. This has been working for some time.
// Connnect with Facebook.
$('.fbLogout').click(function() {
FB.logout();
});
$('.fbLogin').click(function () {
FB.login();
});
FB.init({appId: '163691796982300', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.sessionChange', function() {
location.reload();
});
I recently got a new computer, and my site doesn’t work from this computer. The Facebook login UI seems to work, the auth.sessionChange event is raised, but it looks like the cookie is never supplied and so the page goes into an endless loop of receiving an authentication event, refreshing the page with no cookie and repeating. The problem seems be on this single computer and happens regardless of which browser I use, and which OS I use.
It works on:
- Friend’s PC using Internet Explorer
- Friend’s PC using Firefox Friend’s PC
- Friends PC using Firefox in Ubuntu 10.10 in VirtualBox
- Another PC in the same subnet as new computer
- New computer booting from Ubuntu 10.10 live CD 64-bit
Doesn’t work on:
- New computer using Internet Explorer
- New computer using Chrome
- New computer using Firefox
- New computer using Firefox in Ubuntu 10.10 in VirtualBox
Could this somehow be caused by my network card or network configuration?
Update:
It started working just as mysteriously as it was failing.
This could be the same thing I had to deal with. In your code I can’t see the asynchronous initialization:
This is very important to guarantee that the Facebook JavaScript SDK is fully loaded before you call the init method. Therefore it may suddenly have started working, because the browser already cached the JavaScript file.