0
votes

I have successfully implemented email and Facebook login authentication using Firebase. I would now like to allow email users to link their account with Facebook.

I have the following code for this:

let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)

 if let user = Auth.auth().currentUser {
     user.link(with: credential, completion: { user, error in
         // 
     })
 }

The linking works, but the user returned has no displayName nor photoUrl. Either the user returned in the completion block or when accessing the user via Auth.auth().currentUser.

The user does have a displayName and photoUrl though when authenticating directly with Facebook. Not sure why these properties are nil when linking an account. Any ideas?

1

1 Answers

0
votes

I assume you are first signing up the user with email/password and then linking Facebook to their account. The Firebase Auth backend will not copy the Facebook profile data to the top level displayName and photoURL. However, the solution for this is very easy, you can after linking, copy the Facebook displayName and photoURL from the Facebook currentUser.providerData[indexOfFacebook] and use currentUser.createProfileChangeRequest() to update the displayName and photoURL on currentUser.