views:

1637

answers:

3

Hi All, how to check whether FB Connect session is still valid or not using rails facebooker plugin ? Are there any helper or module that can check the session ? I figure out that if I open up 2 tab in browser, one login with facebook, another is with my site and login using FB Connect. When user trying to logout in my site, facebook will erase both cookie, but when user logout through facebook, it will erase cookie in facebook site only, so the cookie in my site still left behind and I need to check whether the cookie still valid or not...

+3  A: 

Using Facebooker, you'll get an exception when you try to use the exception, which can be rescue_from'd in application.rb

rescue_from Facebooker::Session::SessionExpired, :with => :facebook_session_expired

def facebook_session_expired
  clear_fb_cookies!
  clear_facebook_session_information
  reset_session # remove your cookies!
  flash[:error] = "Your facebook session has expired."
  redirect_to root_url
end
Hugo Duncan
A: 

The fb_logout_link method does not redirect when Facebook session is invalid. Add a redirect callback to your logout_path and it will do the job for you.

    def fb_logout_link(text,url,*args)
      js = update_page do |page|
        page.call "FB.Connect.logoutAndRedirect",url
        # When session is valid, this call is meaningless, since we already redirect
        # When session is invalid, it will log the user out of the system.
        page.redirect_to url # You can use any *string* based path here
      end
      link_to_function text, js, *args
    end
Swanand
+1  A: 

I can't upvote things yet, but the answer that adds the line:

page.redirect_to url

is correct. I'd recommend adding it to Facebooker if Mike is reading.

Andy B.