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