FB Login button not calling onlogin function

10,707

Solution 1

I think you want to be notified about a logged in user either after a login happened or of a user comes to teh page and is already logged in. In this case you have to subscribe to the auth event and handle it:

FB.Event.subscribe('auth.authResponseChange', function(response) { if (response.status === 'connected') { //yourcode } else if (response.status === 'not_authorized') { //your code } else { //yourcode } });

Solution 2

The new facebook login flow says to only display the facebook login button if the user is not currently logged into facebook. If you display it anyway, nothing will happen when they click on it because it will detect that the user is already logged into facebook and so will exit the login process and the post login hook won't be called. The facebook documentation says to first detect whether the user is already logged into facebook, and if they are logged in, grab the facebook uid and simply execute the function you would have called as part of the post login hook. The facebook login button is simply that--a button to log into facebook and not a button to log into your site.

Solution 3

The event says onlogin, so it will only execute when you login through Facebook Connect.

If you are already logged in on Facebook Connect, then the function won't execute because you're already logged in...?

Share:
10,707
JustNeph
Author by

JustNeph

Senior Software Engineer, Pro Wrestler, Livestreamer, Weekend Jedi

Updated on June 28, 2022

Comments

  • JustNeph
    JustNeph almost 2 years

    I have my fb login button created as so

    <fb:login-button perms="email" size="small" onlogin="check_login_session()">Sign Up Using Facebook</fb:login-button>
    

    I have also defined the check_login_session function already as I'm using it on a .click link elsewhere on the page(which does work). However, my problem is when I'm already logged in to FB and I click the button, the FB popup appears, then dissapears and it does nothing. The onlogin is not called nor is any error displayed.

    If I was to logout however, and then click the button, it would give me the fb login prompt, and after filled out and submitted would behave as it is supposed to. It's only when I'm already logged in and I click the FB login button that the issue occurs. Any Ideas?

    Edit: I found that it does call it if I say put alert("Test") in the onlogin but any function I define on the page and try to call it returns saying it's not defined.

  • JustNeph
    JustNeph over 13 years
    But when I'm logged in and press it, it executes the alert which I think means onlogin simply refers to if you are logged in already