FirebaseUI-iOS icon indicating copy to clipboard operation
FirebaseUI-iOS copied to clipboard

Empty diplayName value with SignIn with Apple

Open ghost opened this issue 4 years ago • 11 comments

Step 2: Describe your environment

  • Objective C or Swift: Swift
  • iOS version: 14.5
  • Firebase SDK version: 7.11.1 (SPM - latest)
  • FirebaseUI version: master branche (SPM)

Step 3: Describe the problem:

Steps to reproduce:

  1. Install Firebase UI Auth
  2. Use Apple Sign In
  3. Try to get the displayName value of the Auth variable

Hi everyone,

I use the following code to allow the user to signup via email or Apple. When the user chooses Sign In with Apple the "displayName" property of the current user is empty. I only found a closed Issue where it was mentioned it was implemented.

So I'm curious if you have a tipp for me to get the displayName (name of the user) because I'm not allowed to request it again afterwards due to Apples guidelines.

Thank you!

   @IBAction func LoginButtonTapped(_ sender: UIButton) {
        if let authUI = FUIAuth.defaultAuthUI() {
            authUI.providers = [
                FUIEmailAuth(),
                FUIOAuth.appleAuthProvider()
            ]
            authUI.delegate = self
            
            authUI.tosurl = URL(string: RCValues.sharedInstance.string(forKey: .termsOfServicesUrl))
            authUI.privacyPolicyURL = URL(string: RCValues.sharedInstance.string(forKey: .privacyPolicyUrl))
            
            let authViewController = authUI.authViewController()
            self.present(authViewController, animated: true)
        }
    }
    
    func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) {
        if authDataResult?.user != nil {
            // Call user function to check user data and navigate the user to the next screen
            _ = UserData()
        } 
    }

In the UserData() I then try to access the displayName

       if Auth.auth().currentUser != nil {
            // This is empty with Apple Sign In (with Email it works)
            print(Auth.auth().currentUser?.displayName)
            self.userId = Auth.auth().currentUser?.uid
            ....
        }

ghost avatar May 12 '21 21:05 ghost

More context: See comment https://github.com/firebase/FirebaseUI-iOS/issues/886#issuecomment-839960979 and https://github.com/firebase/FirebaseUI-iOS/issues/886#issuecomment-840100136

weixifan avatar May 24 '21 01:05 weixifan

Thank you for filing this issue; I've filed an internal issue b/189041707 to track this.

weixifan avatar May 24 '21 01:05 weixifan

I'm also seeing this issue. Any update or ETA? Thanks!

neilpatrickadams avatar Jul 10 '21 15:07 neilpatrickadams

A little more info on this issue to help narrow it down...

When I see the empty displayName issue I prompt for the user to enter a name and then use createProfileChangeRequest() to update the display name. This works and I can get the display name correctly from Auth.auth().currentUser UNTIL the user logs out.

Then on the next login the callback: authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) ->authDataResult.user and Auth.auth().currentUser both have the displayName set correct (check right away on the callback) but then very shortly after (after the method has existed) Auth.auth().currentUser displayName is empty.

I'm seeing this with AppleId (using passcode sign-in (haven't tried face))

Display name is used extensively throughout my app so this issue is fairly critical for me :) If you don't think it will be fixed anytime soon please let us know so we can start the unfortunate work around (store and access the username from a local store instead of firebase auth).

Thanks!

neilpatrickadams avatar Jul 10 '21 17:07 neilpatrickadams

@rosalyntan can you take a look at this? Seems to be an issue with upstream Firebase Auth if the name is disappearing after being set.

morganchen12 avatar Jul 12 '21 18:07 morganchen12

Any updates on this? I also have some users without names...

mamilov avatar Jul 30 '21 10:07 mamilov

@rosalyntan any updates or ETA on this one? Thanks!

neilpatrickadams avatar Aug 21 '21 13:08 neilpatrickadams

@morganchen12 @rosalyntan Any updates on this one? We have been waiting patiently :) Thanks!

neilpatrickadams avatar Oct 30 '21 11:10 neilpatrickadams

Hello! This bug should be related (I think) to this one: https://github.com/firebase/firebase-ios-sdk/issues/4393 A workaround is available at the moment but if FirebaseUI is used we cannot implement it. Please not that this issue is currently REJECTING mobile apps who use Apple Sign In, so it should be prioritised. Thanks you

andoma93 avatar Nov 07 '22 15:11 andoma93

FWIW it looks like that firebase-ios-sdk bug has been closed now. Has anyone been able to verify that the FirebaseUI will automatically get this fix? Will it require a version increase?

romrell4 avatar May 18 '23 03:05 romrell4