gpt4 book ai didi

ios - 在Firebase iOS中链接oAuth提供程序

转载 作者:行者123 更新时间:2023-12-01 20:00:08 26 4
gpt4 key购买 nike

我是Firebase和iOS的新手,我想知道是否有人知道如何链接多个oAuth Provider。我关注了Firebase文档并尝试实现此功能:

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")
}
})
}

尽管调用了上面的 FIRAuth.auth()?.currentUser?.link,但从未调用过 debugPrint("APP: \(error)")函数。因为这不起作用,所以我不断收到以下错误:

可选(错误域= FIRAuthErrorDomain代码= 17007 \“该电子邮件地址已被另一个帐户使用。\” UserInfo = {NSLocalizedDescription =该电子邮件地址已被另一个帐户使用。,error_name = ERROR_EMAIL_ALREADY_IN_USE,FIRAuthErrorUserInfoEmailKey = example @ gmail .com})”

任何帮助将不胜感激!谢谢你:D

最佳答案

我相信您对指示感到困惑。在Firebase文档中,它显示为

要将身份验证提供程序凭据链接到现有用户帐户,请执行以下操作:

  • 使用任何身份验证提供程序或方法登录用户。
  • 完成新身份验证提供程序的登录流程,但不包括调用FIRAuth.signInWith方法之一。例如,获取用户的Google ID token ,Facebook访问 token 或电子邮件和密码。
  • 为新的身份验证提供程序
  • 获取FIRAuthCredential

    因此,您不应调用方法FIRAuth.signInWith。我还应该指出,您想创建一个到现有帐户的链接,因此您应该先登录才能链接。这就是为什么您应该拥有currentUser的原因。

    关于ios - 在Firebase iOS中链接oAuth提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40181595/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com