Home Facebook login-button no longer appears after login then logout
Reply: 3

Facebook login-button no longer appears after login then logout

at. Published in 2011-09-04 11:55:39Z

My facebook login-button has been working great:

<fb:login-button length="long" background="light" perms="email"
                 size="medium" onlogin="myLoginCode()"></fb:login-button>

After a user logs in, that facebook login button disappears. On my logout button I have something like this:

<a href="/security_logout" onclick="FB.logout();">logout</a>

When I click there, I'm logged out of both the facebook authentication mechanism and my own site. So then I see the "Log in with Facebook" button again.

Problem is suddenly I noticed when you logout (and FB.logout() is called) the facebook login does not reappear! You are kind of stuck then. What changed? If I call this from Firebug:

FB.getLoginStatus(function(response) {
    if (response.authResponse) alert(response.authResponse);
    else alert("not logged in");

I'll get an alert saying not logged in. However, if I call FB.login(), I get this:

FB.login() called when user is already connected

Any idea what's going on? How do I get the Facebook login-button to reappear after someone has logged out?

Joaquim Rendeiro
Joaquim Rendeiro Reply to 2011-09-04 12:42:27Z

Psychic debugging: FB.logout() makes an AJAX request, that method returns immediately when the request is made, so your browser navigates to your url /security_logout and drops the AJAX connection before the Facebook server has a chance to process it.

I guess you need to look at hooking into the logout response, wait for it to complete and only then navigate to /security_logout, something like this (untested, I just googled the API for FB.logout()):

<a href="#" onclick="my_fb_logout()">logout</a>


function my_fb_logout() {
    FB.logout(function (response) {
        // turn https://www.mywebsite.com/current_path?query_string=xyz#section1
        // into https://www.mywebsite.com
        var url_string = window.location.href;
        var base_url_len = url_string.length - window.location.pathname.length - window.location.search.length;
        var base_url = url_string.substr(0, base_url_len);

        // append /security_logout and redirect to your site's logout page
        var new_url = base_url + "/security_logout";
        window.location.href = new_url;

    // this may not the best way to prevent bubbling of the event (navigating to # in the current page),
    // but will do fine in this case I believe 
    return false;
Anton Melnikov
Anton Melnikov Reply to 2011-09-04 15:43:20Z

You can subscribe to auth.logout with Javascript SDK http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ When the user log out from facebook, you can show the login button again.

j0k Reply to 2012-10-28 09:33:33Z
<div id="fb-btn"><div class='fb-login-button' data-scope='email,user_checkins,offline_access,publish_stream,read_stream'>Facebook</div></div>
<div id='fb-root'></div>
  window.fbAsyncInit = function() {
      appId: '###########',
      cookie: true,
      xfbml: true,
      oauth: true
    FB.Event.subscribe('auth.login', function(response) {
    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        document.getElementById('fb-btn').innerHTML = "<a href='http://###########' class='fb_button fb_button_medium'><span class='fb_button_text'>Facebook</span></a>";
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311288 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO