FB Login button not calling onlogin function

JustNeph picture JustNeph · Nov 4, 2010 · Viewed 10.6k times · Source

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.

Answer

Sven Haiges picture Sven Haiges · Jul 12, 2013

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 } });