首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从firebase注销后从google注销

从firebase注销后从google注销
EN

Stack Overflow用户
提问于 2018-05-14 04:01:55
回答 2查看 1.8K关注 0票数 1

我正在对google帐户使用Firebase身份验证。登录过程运行良好,但我在注销时遇到了问题。我成功地注销了firebase,但没有从google注销。这意味着用户仍然登录到google。我如何才能从这两个系统中注销?

这是我的代码:

代码语言:javascript
复制
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);
    });
}

代码语言:javascript
复制
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的东西。

EN

回答 2

Stack Overflow用户

发布于 2018-05-14 13:34:22

通常,这是预期的行为。从firebase注销与从google注销无关。用户将需要明确地从谷歌注销。但是,如果您知道您的应用程序将在共享设备上使用,则可以执行以下操作:

代码语言:javascript
复制
// 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.
});
票数 2
EN

Stack Overflow用户

发布于 2018-12-13 20:11:54

mGoogleSignInClient.signOut().addOnCompleteListener(ClassName.this,OnCompleteListener() { @Override public void onComplete(@非空任务任务){ Toast.makeText(ClassName.this,"logged“,Toast.LENGTH_SHORT).show();} });

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50320147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档