从Firebase注销后从Google注销 [英] Logout from google after login out from firebase

查看:73
本文介绍了从Firebase注销后从Google注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对Google帐户使用Firebase身份验证.登录过程工作正常,但注销时遇到问题.我成功注销了Firebase,但未从Google注销.这意味着用户仍然登录到google.我怎样才能从他们两个中注销?

I'm using Firebase authentication with google accounts. Login process works fine, but I have a problem with logout. I successfuly log out of firebase, but not from google. That means that the user remains logged in to google. How can I log out from both of them?

那是我的代码:

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的任何内容.

I've seen this post, speaking about similar issue on android, but can't find anything for JS.

推荐答案

通常,这是预期的行为.从Firebase注销与从Google注销无关.用户需要从Google显式退出.但是,如果您知道您的应用程序将在共享设备上使用,则可以执行以下操作:

Normally this is expected behavior. Sign out from firebase is unrelated to sign out from google. User would need to explicitly sign out from google. However, if you know your application will be used on a share device you can do the following:

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

这篇关于从Firebase注销后从Google注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆