Firebase auth linking error - User can only be linked to one identity for the given provider

家住魔仙堡 提交于 2019-12-24 08:30:00

问题


When users first run my app it creates an anonymous account for them, which if they decide to use higher level features, will be converted to an email authenticated account

Code for anon sign in is straightforward (taken directly from the docs)

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

When registering, I create a new account with email credentials and link to the anonymous account like so

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

Problem is every single time I get the "User can only be linked to one identity for the given provider"

and I have no accounts registered in Firebase at all

Accounts, anonymous and email auth are successfully created but just cannot link


回答1:


You can't link 2 existing Firebase users. You can only link a new credential to an existing user. When you are registering the user, you should just currentUser.linkWithCredential on the anonymous user using the email/password credential without calling createUser first. This is basically upgrading the anonymous user to an email/password user.



来源:https://stackoverflow.com/questions/46135248/firebase-auth-linking-error-user-can-only-be-linked-to-one-identity-for-the-gi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!