javascript - 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);
});
}
我试过隐身模式。进入谷歌信用,进入应用程序,并决定退出。点击登录谷歌,它会自动将我带到应用程序。
有什么建议吗?
解决方案
您可能真的不想在浏览器中退出 Google(因为它会使您退出 Gmail,以及您正在使用 Google 应用程序的任何其他选项卡/窗口)。当您再次点击 Firebase auth 时,它会直接跳入应用程序(绕过 Google 登录,因为它从未真正从 Google 注销)。您可能不想立即登录,而是希望查看 Google 帐户选择器。如果是这样,这是我对相关 SO 问题的回答。
请注意,您描述的问题只会在您仅登录一个 Google/Gmail 帐户时发生,即,就像您在 incog 模式下一样。如果您已登录 >1,您将始终获得帐户选择器,以便 Firebase 可以告诉您的应用您选择了哪个用户。
推荐阅读
- html - 不同路线的不同图标
- ffmpeg - 使用 FFmpeg AutoGen 保存到位图适用于 Windows,但不适用于 Linux
- python - 在 React 文件夹结构中将杂项文件、脚本放在哪里?
- excel - 基于excel数字计数的IF语句
- c - 更改按钮样式(C win32)
- ios - 您的规范来源都不包含满足依赖项的规范:Firebase (~> 6.33.0)、Firebase (= 6.33.0, ~> 6.33.0)
- javascript - 如何在使用 jquery 填写表单之前禁用提交表单按钮?
- php - 为 Laravel 8 路由定义命名空间
- javascript - 使用 React Hooks,使用“useState”和“useEffect”,有没有办法渲染一个状态,直到状态有一个值?
- python - python __module__ dunder 是 __main__