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