2017-01-19 43 views
0

我將谷歌和Facebook登錄集成到我的網站。並設置一個條件,一個人可以用FB或谷歌登錄。現在問題是我的谷歌登錄功能自動工作,如果我的Gmail帳戶是在同一瀏覽器中打開。避免谷歌登錄功能在每個頁面上呼叫

function loggedOut(href){ 
    gapi.load('auth2', function() { 
       gapi.auth2.init(); 
    }); 
     setTimeout(function(){ 
     var auth2 = gapi.auth2.getAuthInstance(); 
     auth2.signOut().then(function() { 
      //console.log('User signed out.'); 
      document.location = href; 
     }); 

     }, 2000); 
} 

function onSignIn(googleUser) { 
    var profile = googleUser.getBasicProfile(); 
    var fullName = profile.getName(), 
    imageUrl = profile.getImageUrl(), 
    email = profile.getEmail(), 
    provider = 'Google'; 
    $.ajax({ 
     url: 'includes/google-login.php', 
     type: 'POST', 
     data: { provider: provider, fullName :fullName, imageUrl : imageUrl, email: email }, 
     success: function(data){ 
      console.log(data); 
      if(data == 1){ 
       location.reload(); 
      } else if(data.trim().match("^Entered")){ 
       alert(data); 
       loggedOut('This Page URL'); 
      } 
     } 
    }); 
}; 

$('#log-out').on('click', function(e){ 
    e.preventDefault(); 
    var href = $(this).attr('href'); 
    loggedOut(href); 
}); 

回答

0

var auth2 = gapi.auth2.getAuthInstance();

把它放在一個函數中,稱爲登錄,只在用戶點擊登錄按鈕時調用它。這應該防止谷歌自動檢測用戶。或者你可以完全刪除這條線。