且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当用户退出我的Firebase应用程序时,为什么不从身份验证提供程序也退出?

更新时间:2023-01-04 11:41:39

主要答案:

@Shib 提供的答案基本上是正确的,但没有为到达这里的每个人提供足够的背景信息,所以让我详细说明.当您的代码调用firebase.auth().signOut()时,您从应用程序中退出了Firebase,但没有整体上从身份验证提供程序中退出(更多信息在下面的链接中),因为您确实不想在其他标签中退出Gmail和其他Google , 正确的?

The answer provided by @Shib is basically correct but doesn't provide enough context for everyone arriving here, so let me elaborate. When your code calls firebase.auth().signOut(), you sign out of Firebase from your app, but not the auth provider overall (more in links below) because you don't really want to be signed out of your Gmail and other Google in your other tabs, right?

仅当您的浏览器缓存中只有单个 Google登录名时,才会发生您遇到的问题.在这种情况下,下次您使用Firebase身份验证登录时,它将自动重用相同的Google凭据(因为您也没有退出Google,也是这样),以使用户能够以更少的鼠标单击次数更快地登录

The issue you're running into only occurs if only a single Google login is available in your browser cache. If this is the case, the next time you use Firebase auth to login, it will automatically reuse the same Google credentials (since you didn't sign out of Google, and also, it's) to enable users to login faster with fewer mouse clicks.

IOW,对于过去使用> 1个Google/Gmail帐户登录的用户来说,这不是一个问题-这些用户将获得预期的帐户选择器对话框.如果您只有一个Google登录名,并且想要想要查看帐户选择者,则需要设置select_accountprompt自定义参数,如@Shib所指出的:

IOW, it's not an issue for users who have signed-in with >1 Google/Gmail accounts in the past -- these users will get the expected account-picker dialog. If you only have a single Google login available and want to see the account-picker, you need to set the prompt custom parameter to select_account as @Shib noted:

var provider = new Firebase.auth.GoogleAuthProvider();
  provider.setCustomParameters({
    prompt: 'select_account'
  });

要了解有关通过Firebase身份进行Google登录的更多信息,请参见此页.这是帖子,其中更详细地描述了此行为.上方 @linasmnew @bojeil 为什么他们评论说(未退出身份验证提供程序)这是默认值/预期值行为,因此这是一个线程,提供了 说明.

To learn more about doing Google sign-in from Firebase auth, see this page. Here's a post which describes this behavior in more detail. Above, @linasmnew asked @bojeil why they commented that this (not signing out of the auth provider) is the default/expected behavior, so here is a thread providing that explanation.

PART 2 ( FirebaseUI库使用仅):

如果您使用的是便捷库(位于Firebase身份验证的顶部),如果您只有一个Google凭据,也会遇到此问题,但是解决该问题可能并不那么简单.该库的目的是提供一个可重用的预制UI,允许用户从各种身份验证提供者中进行选择减少开发人员时间并提供一致的用户体验.

If you're using this convenience library (which sits atop Firebase auth), you'll also run into this if you have a single Google credential, but it may not be as straightforward how to fix the issue. The purpose of this library is to provide a reusable prebuilt UI letting users choose from various auth providers to reduce developer time and provide a consistent user experience.

开发人员在其signInOptions配置中列出受支持的提供商ID (特别是步骤3). ( Python 3 Google App Engine构建应用"快速入门示例使用FirebaseUI,这是遇到此问题的地方.)

Instead of instantiating a specific auth provider class like in the main answer above, developers list out the supported provider IDs in their signInOptions config (specfically step 3). (The Python 3 Google App Engine "building an app" Quickstart example uses FirebaseUI, and that's where I ran into this issue.)

例如,如果您决定仅使用Google和电子邮件身份验证,则这些选项如下所示:

For example, if you decide on using just Google and email auth, those options look like this:

signInOptions: [
  firebase.auth.GoogleAuthProvider.PROVIDER_ID,
  firebase.auth.EmailAuthProvider.PROVIDER_ID,
  //firebase.auth.FacebookAuthProvider.PROVIDER_ID,
  //firebase.auth.TwitterAuthProvider.PROVIDER_ID,
  //firebase.auth.GithubAuthProvider.PROVIDER_ID,
  //firebase.auth.PhoneAuthProvider.PROVIDER_ID
],
            . . .

这正是App Engine示例所做的,并且嵌入HTML .)当此错误(功能"(um,"feature"))收到不想要的头此处,添加该prompt自定义参数以强制显示帐户选择器,如下所示:

This is exactly what the App Engine sample does, and here's the code. (This FirebaseUI JS can also be embedded in HTML.) When this bug (um, "feature") rears its undesired head here, add that prompt custom parameter to force the account-picker to show up like this:

signInOptions: [
  //firebase.auth.GoogleAuthProvider.PROVIDER_ID,
  { provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID,
      customParameters: { prompt: 'select_account' },
  }
  firebase.auth.EmailAuthProvider.PROVIDER_ID,
  //firebase.auth.FacebookAuthProvider.PROVIDER_ID,
  //firebase.auth.TwitterAuthProvider.PROVIDER_ID,
  //firebase.auth.GithubAuthProvider.PROVIDER_ID,
  //firebase.auth.PhoneAuthProvider.PROVIDER_ID
],
            . . .