Facebook auto login - notify user

838 Views Asked by At

I am allowing my users to login to my web-app using their Facebook account.

A user is auto-logged in to my website through Facebook if -

  • They are registered to my site using Facebook
  • They haven't logged out of my site and ended their session
  • They are currently signed into Facebook

This is fine, except, there is a pause between the user accessing the homepage and being taken to their dashboard whilst Facebook checks whether they have logged in. Is there a way to show a sort of pre-loader that says "Signing in with Facebook" whilst the transition is made?

I am using the following Facebook javascript -

<script>
  window.fbAsyncInit = function() {
              FB.init({
                appId      : 'xxxxxxxxx',
                status     : true, 
                cookie     : true,
                xfbml      : true,
                oauth      : true,
              });

              FB.Event.subscribe('auth.login', function() {
                  FB.api('/me', function(response) {
                window.location='mysite/fb_signin/';
                  });
              });

            };
            (function(d){
               var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
               js = d.createElement('script'); js.id = id; js.async = true;
               js.src = "//connect.facebook.net/en_US/all.js";
               d.getElementsByTagName('head')[0].appendChild(js);
             }(document));

          </script>

Thank you.

2

There are 2 best solutions below

0
On

I agree with Marc that you can use the getLoginStatus() to help you determine what they are before you send them to one place or another. However, you said something was slow. So that led me to look at your code, and it appears you're missing the channelUrl in your FB.init() call (see https://developers.facebook.com/docs/reference/javascript/ for more information). without the channelUrl user interaction with the Javascript SDK functions will be sluggish and slow.

0
On

With the facebook api you are able to check if the user is connected or not before doing to call to FB.api (that is what taking time).

http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

This should help