且构网

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

如何确定 Firebase 用户是否使用 Facebook 身份验证登录

更新时间:2022-06-20 18:58:04

在 3.x 版及更高版本中,单个用户可以使用多个提供程序登录.所以不再有单一提供者 ID 的概念.事实上,当你打电话时:

In version 3.x and later a single user can be signed in with multiple providers. So there is no longer the concept of a single provider ID. In fact when you call:

FirebaseAuth.getInstance().getCurrentUser().getProviderId()

它总是会返回firebase.

要检测用户是否使用 Facebook 登录,您必须检查提供商数据:

To detect if the user was signed in with Facebook, you will have to inspect the provider data:

for (UserInfo user: FirebaseAuth.getInstance().getCurrentUser().getProviderData()) {
  if (user.getProviderId().equals("facebook.com")) {
    System.out.println("User is signed in with Facebook");
  }
}