Firebase身份验证链接错误-用户只能链接到给定提供者的一个身份 [英] Firebase auth linking error - User can only be linked to one identity for the given provider

查看:75
本文介绍了Firebase身份验证链接错误-用户只能链接到给定提供者的一个身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户首次运行我的应用程序时,它会为他们创建一个匿名帐户,如果他们决定使用更高级别的功能,它将被转换为通过电子邮件验证的帐户

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"

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

and I have no accounts registered in Firebase at all

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

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

推荐答案

您不能链接2个现有的Firebase用户.您只能将新凭据链接到现有用户. 在注册用户时,应仅使用电子邮件/密码凭据对匿名用户使用currentUser.linkWithCredential,而无需先调用createUser.这基本上是将匿名用户升级为电子邮件/密码用户.

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.

这篇关于Firebase身份验证链接错误-用户只能链接到给定提供者的一个身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆