12
votes

I am using the code provided by Firebase for Google Authentication and somehow, the authentication was successful but the email was not correctly imported to Firebase.

https://firebase.google.com/docs/auth/ios/google-signin

As you can see in the screenshot below, the email is blank. When I looked at the debugger, it is showing nil.
I clicked allow viewing email during authentication but I think there are still some settings that was not done correctly. Could someone help me to take a look? I am interested to use the email to create the username for each user.

enter image description here

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
    if let error = error {
        print(error.localizedDescription)
        return
    }

    let authentication = user.authentication
    let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,
                                                                 accessToken: authentication.accessToken)
    FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
        if error != nil {
            print(error?.localizedDescription)
            return
        }

        print("User logged in with Google...")
        self.performSegueWithIdentifier("ToHome", sender: nil)
    }
}
2
do you want to have multiple accounts with the same email?adolfosrs
I just disabled multiple accounts. Now I am getting the email...thx...Daryl Wong
It sounds like between the two of you, you have an answer. Can one of you write it up?Frank van Puffelen
@FrankvanPuffelen just did it. I still have one doubt, can you confirm if my last paragraph make sense?adolfosrs
When in doubt, I'd remove that statement. ;-)Frank van Puffelen

2 Answers

13
votes

The email is not showing on firebase console because you are allowing users to create multiple accounts with the same email. If you navigate to Auth -> Sign-in method you can set the option to Avoid creating multiple accounts with the same e-mail. After doing so the emails will start to appear when creating the user.

enter code here

Not sure here but, if you still want to create multiple accounts and have the user email on the application side I guess that you will need to store the email on firebase database when creating the user.

-1
votes

You can search in list ProviderData:

userFirebase.providerData

The providerId "google.com" as usual have the email.