Windows State Change Authenticator running twice?

When my page loads, I need to know if the user is logged in and performing different tasks on it. The first thing I do is check if they are logged in, but for some reason the operator if

checks that it is being checked twice. Here is my code:

override func viewDidAppear(_ animated: Bool) {
    FIRAuth.auth()?.addStateDidChangeListener { auth, user in
        if let user = user {
           print("User is logged in")
        }

      

"User logged in" is printed twice to the console on page load, not just once. Am I doing something wrong?

+3


source to share


1 answer


i faced the same problem. and it is not logged in. it might collide with the current option   https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth.AuthStateListener

  • Immediately after registering a listener
  • When a user subscribes
  • When displaying the current user
  • When changing the current user
  • When changing the user's current token

so just put in the flag and then check it. or check the answer nil

or not



Try this way:

override func viewDidAppear(_ animated: Bool) {
    FIRAuth.auth()?.addStateDidChangeListener { auth, user in
        if let user = user {
            if user != nil {
               print("User is logged in")
           }
        }

      

Note: try using flag

and checkuser =! nil

+1


source







All Articles