首页 > 解决方案 > Firebase google auth 未完全退出

问题描述

使用谷歌提供的非常清晰的简单示例(Firebase Google Auth)我无法从谷歌注销。

每次登录时,我都使用按钮调用此方法,它允许我登录并将我导航到本地主机。

function logGoogle() {

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;
  // The signed-in user info.
  var user = result.user;
  location.href = 'http://localhost:8080';
  // ...
}).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(errorCode);
  console.log(errorMessage);
  console.log(email);
  console.log(credential);
});

}

但是,当我返回包含注销按钮的主菜单时。它会注销会话,不会删除会话。当我重新登录时,我不需要输入谷歌信用。请记住,我使用 gmail 帐户登录到 google chrome。

function logOutGoogle() {
  firebase.auth().signOut().then(function () {
    console.log("you logged off");

   
 location.href = 'http://localhost/GoogleVue3/';
  }).catch(function (error) {
    alert(error);
  });
}

我试过隐身模式。进入谷歌信用,进入应用程序,并决定退出。点击登录谷歌,它会自动将我带到应用程序。

有什么建议吗?

标签: javascriptfirebasefirebase-authentication

解决方案


您可能真的不想在浏览器中退出 Google(因为它会使您退出 Gmail,以及您正在使用 Google 应用程序的任何其他选项卡/窗口)。当您再次点击 Firebase auth 时,它会直接跳入应用程序(绕过 Google 登录,因为它从未真正从 Google 注销)。您可能不想立即登录,而是希望查看 Google 帐户选择器。如果是这样,这是我对相关 SO 问题的回答。

请注意,您描述的问题只会在您仅登录一个 Google/Gmail 帐户时发生,即,就像您在 incog 模式下一样。如果您已登录 >1,您将始终获得帐户选择器,以便 Firebase 可以告诉您的应用您选择了哪个用户。


推荐阅读