我在Google帐户中使用Firebase身份验证。登录过程工作正常,但我有登出问题。我成功退出了firebase,但不是谷歌。这意味着用户仍然登录谷歌。我怎样才能退出?
那是我的代码:
function auth() {
// Initialize Firebase;
firebase.initializeApp(settings);
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
sessionStorage.setItem('tokenK', token);
// The signed-in user info.
var user = result.user;
var tempName = user.displayName.split(" ");
var fullName = tempName[0].charAt(0).toUpperCase() + tempName[0].toLowerCase().substring(1, tempName[0].length) +
" " + tempName[1].charAt(0).toUpperCase() +tempName[1].toLowerCase().substring(1, tempName[1].length);
sessionStorage.setItem('displayName', fullName);
sessionStorage.setItem('userName', user.email);
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
console.log(error);
});
}
和
function logOut(){
firebase.initializeApp(settings);
var dataJ = JSON.stringify(sessionStorage.getItem('userName'));
var xhttp = new XMLHttpRequest();
firebase.auth().signOut().then(function() {
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 204) {
sessionStorage.removeItem('tokenK');
sessionStorage.removeItem('displayName');
sessionStorage.removeItem('userName');
sessionStorage.removeItem('role');
sessionStorage.removeItem('school');
sessionStorage.removeItem('grade');
window.open('index.html', '_self');
}
};
xhttp.open("POST", settings.protocol + "://" + settings.host + ":" + settings.port + "/api/Login/SignOut", true);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.setRequestHeader("Token", sessionStorage.getItem('tokenK'));
xhttp.send(dataJ);
}).catch(function(error) {
console.log(error);
});
}
我已经看过这篇文章,谈到Android上的类似问题,但找不到JS的任何内容。
答案 0 :(得分:2)
通常这是预期的行为。从firebase退出与从谷歌退出无关。用户需要明确退出谷歌。但是,如果您知道您的应用程序将在共享设备上使用,则可以执行以下操作:
// Sign out from firebase.
firebase.auth().signOut().then(function() {
// Redirect to google sign out.
window.location.assign('https://accounts.google.com/logout');
}).catch(function(error) {
// Error occurred.
});
答案 1 :(得分:0)
mGoogleSignInClient.signOut()。addOnCompleteListener(ClassName.this,new OnCompleteListener(){ @Override 公共无效onComplete(@NonNull任务任务){ Toast.makeText(ClassName.this,“登出”,Toast.LENGTH_SHORT).show(); } });