I use Firebase Authorization to log in to the iOS app via Facebook and Google. I encode Swift. When the application starts, I need to check if the user is already signed up to present the correct ViewController (for example, if no one is signed up, I represent the login controller, otherwise I represent the Home View controller). If I use the “lightweight” solution offered by Firebase, it means
if FIRAuth.auth()?.currentUser != nil { // User is signed in. // ... } else { // No user is signed in. // ... }
Therefore, if the current user is not equal to zero, this happens just so that a Firebase warning may occur ( https://firebase.google.com/docs/auth/ios/manage-users ).
"Note: currentUser may also be nil because the auth object did not complete initialization. If you use a listener to track login status, you do not need to handle this case."
So, I would like to implement a listener as suggested in the manual:
handle = FIRAuth.auth()?.addStateDidChangeListener() { (auth, user) in
The listener will also process the intermediate status so that it is triggered when the Auth object is created. Point, I really can't get it to work correctly. Can someone help me use this listener to check if a user is registered?
thanks
source share