Linking oAuth Providers in Firebase iOS
我是 Firebase 和 iOS 的新手,我想知道是否有人知道如何链接多个 oAuth 提供程序。我按照 Firebase 文档并尝试实现此功能:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | func firebaseSignInWithLink(credential: FIRAuthCredential) { FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in if error != nil { debugPrint("APP: there has been an error signing into firebase, perhaps another account with same email") debugPrint("APP: \\(error)") // if existing email, try linking FIRAuth.auth()?.currentUser?.link(with: credential, completion: { (user, error) in if error != nil { debugPrint("APP: there has been an error signing into firebase") debugPrint("APP: \\(error)") } else { debugPrint("APP: successfully signed into firebase") } }) } else { debugPrint("APP: successfully signed into firebase") } }) } |
尽管上面的
Optional(Error Domain=FIRAuthErrorDomain Code=17007 "The email address is already in use by another account." UserInfo={NSLocalizedDescription=The email address is already in use by another account., error_name=ERROR_EMAIL_ALREADY_IN_USE, [email protected]})"
任何帮助将不胜感激!谢谢 :D
我相信您对这些说明感到困惑。在 firebase 文档中,它读取
要将身份验证提供程序凭据链接到现有用户帐户:
完成新身份验证提供程序的登录流程,直到(但不包括)调用 FIRAuth.signInWith 方法之一。例如,获取用户的 Google ID 令牌、Facebook 访问令牌或电子邮件和密码。
为新的身份验证提供程序获取 FIRAuthCredential
所以你不应该调用 FIRAuth.signInWith 方法。我还应该指出,您想要创建一个指向现有帐户的链接,因此您应该先登录,然后才能链接它。这就是为什么你应该有一个 currentUser。
这是因为从 firebase 控制台取消选中"每个电子邮件地址的多个帐户设置 firebase 设置"。