Looping login with Facebook JS SDK and Rails
- by nafe
I'm using the Facebook JS SDK for single-sign with my rails app. I translated the php code from the Facebook example (at the bottom of the page under "Single Sign-on with the JavaScript SDK") into ruby.
This appeared to be working great but I've noticed one user that gets continual redirects when trying to login. The logs look like:
Processing UsersController#login (for X.X.X.X at 2010-05-22 17:25:55) [GET]
Redirected to http://myapp.com/
Completed in 0ms (DB: 0) | 302 Found [http://myapp.com/login]
(times as many entries as my unfortunate user leaves the browser redirecting in a loop).
My client side code includes a callback with the "auth.sessionChange":
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
window.location = "/login";
} else {
// The user has logged out, and the cookie has been cleared
window.location = "/logout";
}
});
So it seems to me like this event is continually firing. Although, I can't test this theory because I can't recreate this scenario locally.
I don't think it's the rails controller. The code here is just:
def login
# if first time user create db entry
# now redirect back to where the user came from
begin
redirect_to :back
rescue ActionController::RedirectBackError
redirect_to root_url
end
end
Does anyone have any idea on what's going on?