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

If you press Cancel on the authViewController, didSignInWithUser gets called on the delegate with an error and after that the FIRUser object becomes nil

Open yorgosg opened this issue 10 years ago • 4 comments

Hi again,

I have noticed that after the authViewController is launched, if you press Cancel without performing any other action, then the didSignInWithUser gets called on the delegate with the following error:

<Warning>: Error Domain=FIRAuthUIErrorDomain Code=1 "The operation couldn’t be completed. (FIRAuthUIErrorDomain error 1.)"

This behaviour is done every time and on actual devices on iOS 7,8 and 9.

Also, right after entering the didSignInWithUser, the FIRUser object becomes nil.

I have the following code in place but in this case it is not called to reset the user.

[[FIRAuth auth] addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth,
                                                FIRUser *_Nullable user) {
     if (user != nil) {
        // User is signed in.
     } else {
        // No user is signed in.
    }
}];

Any thoughts? I appreciate any feedback.

I am using Xcode 7.2, Cocoapods 1.0.0 and the following Firebase pods: Using Firebase (3.5.2) Using FirebaseAnalytics (3.3.1) Using FirebaseAuth (3.0.4) Using FirebaseDatabase (3.0.2) Using FirebaseInstanceID (1.0.8) Using FirebaseMessaging (1.1.1) Using FirebaseUI (0.5.5)

yorgosg avatar Sep 16 '16 11:09 yorgosg

Hi yorgosg!

It should be working fine. Let me explain.

When you press cancel on authViewController: a) if you are logged-in:

  1. addAuthStateDidChangeListener: calls FIRAuthStateDidChangeListenerBlock. It passes current logged user (you canceled new user login, yeah? - so we pass to method current user)
  2. - (void)authUI:(FIRAuthUI *)authUI didSignInWithUser:(nullable FIRUser *)user error:(nullable NSError *)error is called and it passes nil user (because no new user is logged-in) error code is 1. This is value of FIRAuthUIErrorCodeUserCancelledSignIn declared in FirebaseAuthUI/FIRAuthUIErrors.h

b) if you are not logged in

  1. FIRAuthStateDidChangeListenerBlock user param is nil (that's it: current user is nil)
  2. didSignInWithUser works the same as in a.2

Also you can always get current logged-in user by calling [FIRAuth auth].currentUser Please let us know what breaks your functionality.

yramanchuk avatar Sep 16 '16 17:09 yramanchuk

Hi yramanchuk, thank you very much for the prompt reply, I appreciate it. Congrats on contributing to this amazing work dude.

Well, it makes sense now, if code 1 stands for FIRAuthUIErrorCodeUserCancelledSignIn, so great. Also, It turns out that the user object was nil because I had signed the user out at some point. I sign in the users anonymously so I was not used to seeing the user object nil and I thought it had something to do with the didSignInWithUser returning an error. So, a false alarm on that one :) I probably need to sign in anonymously again post signing out.

One more thing, does FirebaseUI support the conversion from an anonymous account to a permanent account? I tried converting an anonymous user to a permanent one by signing in with a Facebook account that hadn't been used before in Firebase auth, but the Facebook signed in user was given a new user id. Should it do that or should it keep the same user id as the anonymous user?

Please let me know, cheers.

yorgosg avatar Sep 17 '16 16:09 yorgosg

does FirebaseUI support the conversion from an anonymous account to a permanent account?

This is something we're looking into, and requires support from the upstream Firebase library first.

morganchen12 avatar Sep 19 '16 17:09 morganchen12

Filed #139 for tracking anon account conversion

alfongj avatar Sep 19 '16 19:09 alfongj