带有 Facebook 和 User/Password 身份验证的 Firebase

Firebase with Facebook and User/Password Authentication

我正在为我的应用程序使用 firebase 实现 facebook 登录。 objective 是开发一个逻辑,用户可以使用 email/password 提供者或 facebook 提供者登录。当我开始开发时,我发现了两种方法来做我想做的事:

1 - Link Facebook 到 email/password 供应商:

2 - 在 firebase 上使用同一电子邮件启用多个帐户:

结论

有什么我想念的吗?当用户注册 facebook 时,我尝试使用 updateEmail() 但它只是更新了 facebook 提供商的电子邮件属性。我真的必须让用户输入他的密码才能在两个提供商之间创建 link 吗?

为了方便通过firebase.auth().signInWithRedirect()firebase.auth().linkWithRedirect()等方法提供用户个人资料信息,则Firebase项目需要配置One account per email address (Firebase Console > Authentication > Sign-in method)。这是最简单的(也是默认的)配置。

原题陈述:

I don't want the user to insert his password for email/password provider just to link to his facebook provider.

  • 如果用户始终使用相同的提供商方法登录(例如 Facebook、密码、电子邮件 link、Google 登录),则 he/she 将永远不需要 link 个帐户。

  • 对于想要使用多个提供商登录的用户,帐户 linking 是一种简单的用户体验,并且只会在第一个 linking 提供商。

关联账户

  • 当 Firebase 项目配置为 One account per email address 时,当用户第一次尝试使用其他提供商登录时,您将收到 Firebase 错误 auth/account-exists-with-different-credential.

  • 通过调用 firebase.auth.Auth.fetchSignInMethodsForEmail 然后要求用户使用返回的提供商之一登录来解决此问题。

  • 用户登录后,可以使用 firebase.User.linkWithCredential

    将原始凭据 linked 给用户

请注意,帐户 linking 适用于任何提供商组合。因此,如果用户首先使用 email/password 注册然后决定使用 Facebook 登录,反之亦然,这并不重要。