Firebase身份验证链接错误 - 用户只能链接到给定提供商

时间:2017-09-09 21:25:44

标签: swift firebase firebase-authentication

当用户首次运行我的应用时,会为他们创建一个匿名帐户,如果他们决定使用更高级别的功能,则会转换为经过身份验证的帐户

匿名登录代码很简单(直接从文档中获取)

// No user is signed in.
Auth.auth().signInAnonymously() { (usr, err) in
    if (err == nil) {
        print("Anon User ID \(usr!.uid)")
    } else {
        print("Anon auth error \(String(describing: err!.localizedDescription))")
    }
}

注册时,我创建了一个包含电子邮件凭据的新帐户,并链接到匿名帐户,如此

Auth.auth().createUser(withEmail: email, password: password) { (user, err) in
    if (err != nil) {
        print("Error registering \(String(describing: err!.localizedDescription))")
    } else {
        let credential = EmailAuthProvider.credential(withEmail: email, password: password)
        Auth.auth().currentUser!.link(with: credential, completion: {(user, err) in
            if (err != nil) {
                // Error
            } else {
                // Linked
            }
        })
    })

问题是每次我得到"用户只能链接到给定提供商的一个身份"

我根本没有在Firebase中注册的帐户

帐户,匿名和电子邮件身份验证已成功创建,但无法链接

1 个答案:

答案 0 :(得分:1)

您无法关联2个现有Firebase用户。您只能将新凭据链接到现有用户。 当您注册用户时,您应该if (a==b) if (b==c) if (c==d) return (a,1) else return (a,d,2) else if (c==d) return (a,c,2) else if (a==d) return (a,c,2) else return (a,c,d,3) else if (b==c) if (c==d) return (a,b,2) else if (a==d) return (a,b,2) else return (a,b,d,3) else if (c==d) if (a==c) return (a,b,2) else return (a,b,c,3) else if (a==c) if (b==d) return (a,b,2) else return (a,b,d,3) else if (b==d) return (a,b,c,3) else if (a==d) return (a,b,c,3) else return (a,b,c,d,4) 使用电子邮件/密码凭据匿名用户,而无需先调用createUser。这基本上是将匿名用户升级为电子邮件/密码用户。