Reputation: 2529
In order to pre-register someone in my beta app I added them to my Firebase Auth users via email. One they open the app for the first time they get a login challenge (all great so far). They login using the "Google Signin" button and use the same email address. Firebase allows them in, and uses the same auth'ed user I pre-created earlier. (Still great.)
The problem is: When the users logs in using "Google Sign in" their name and photo are not added to their profile. Keep in mind, if they logged in using "Google Sign in" first, I would have captured the extra profile info, AND it seems like the "Google Sign in" works, but I cant seem to get the display name and photo.
Is there a way to force a refresh of the profile info so I can pull their display name and photo?
(This is the basic login I use after manually adding their email in Firebase's "Dashboard")
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
NotificationCenter.default.post(name: Notification.Name(CustomNotifications.AppLoginStart), object: nil)
if let error = error {
print("Error while Google Sign In - \(error)")
NotificationCenter.default.post(name: Notification.Name(CustomNotifications.AppLoginFailure), object: nil)
return
}
// Google Authorisation
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)
// Firebase Authorisation
Auth.auth().signIn(with: credential) { (user, error) in
if let error = error {
print("Error while Firebase Auth - \(error)")
NotificationCenter.default.post(name: Notification.Name(CustomNotifications.AppLoginFailure), object: nil)
return
}
// Success
print("Firebase Login Successful.")
print("Firebase Login.", user!, user!.displayName ?? "No display Name")
FirebaseHelper.sharedInstance.updateUserDetails(uid: user!.uid, email: user!.email!, name: user!.displayName, avatar: user?.photoURL)
NotificationCenter.default.post(name: Notification.Name(CustomNotifications.AppLoginSucess), object: nil)
}
}
Upvotes: 3
Views: 1342
Reputation: 475
The main issue is that you have to multiple providers. The user object will by default have information about the first authenticated provider. In your case, the email provider.
So when the user logs in with facebook, the profile with not be updated with those details, but the details (imageURL, Name, ...) will be added to providerData
which is an array of provider data.
So you'll need to get the last entry in providerData
or filter by
providerId
:
https://firebase.google.com/docs/auth/web/manage-users#get_a_users_provider-specific_profile_information
Upvotes: 1
Reputation: 475
Have you tried to call the reload()
method on the FIRUser
after login ?
-reloadWithCompletion:
Reloads the user’s profile data from the server.
Upvotes: 0