Issue with addAuthStateDidChangeListener being called twice

Jamie22

I'm working with Firebase and per their docs, I'm checking to see whether or not a user's logged in state changes. The problem resides in the listener block, where the code is being called twice when the apps launched (user's logged in). It's not too much of a deal, but Firebase is creating two values in connections and removing both. How would I fix this issue? I'd need to call it after the user is obtained in the listener though and not outside because there is no guarantee that user will exist outside that block if it's not finished getting the user data first.

FIRAuth.auth()?.addAuthStateDidChangeListener { auth, user in
        if let theUser = user {
            // User is signed in.

            // CODE IN HERE IS CALLED TWICE UPON APP LAUNCH (WHEN USERS LOGGED IN).... WHY?
            self.currentUser = theUser
            print("LOGGED IN!!!!")


            self.updateUsersStatus(user: self.currentUser)

        } else {
            // No user is signed in.
            self.performSegueWithIdentifier(SEGUE_LOG_IN, sender: self)
        }
    }
Doug

+ click or option + click on the addAuthStateDidChangeListener function. You will see the following:

Registers a block as an "auth state did change" listener. To be invoked when:
    - The block is registered as a listener,
    - The current user changes, or,
    - The current user's access token changes.

To summarize - the block get's called immediately and then most likely gets called again after verifying the FIRApp and/or FIRAuth objects do not contain any stale data. So the behavior of invoking the callback twice should be expected and managed appropriately.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

HandleFunc being called twice

From Dev

page being called twice

From Dev

Why is viewDidLoad being called twice

From Dev

Why constructor is being called twice

From Dev

JS function being called twice?

From Dev

ViewPager Fragment being called twice

From Dev

Why constructor is being called twice

From Dev

Callback function being called twice

From Dev

Constructor of Part is being called twice

From Dev

Why is viewDidLoad being called twice

From Dev

Bind data to specific blade templates in Laravel 5.1 (Issue with view composer being called twice on nested template)

From Dev

Meteor Router data function being called twice

From Dev

Why is my onCreateView method being called twice?

From Dev

Prevent on('click') from being called twice

From Dev

javascript click being called twice and more

From Dev

Ninject, WebAPI and ExceptionFilterAttribute being called twice

From Dev

AngularJS Service in directive being called twice

From Dev

Controller being called twice in Ionic (AngularJS)

From Dev

Why DTM Data Element is being called twice?

From Dev

For some reason, paint() is being called twice

From Dev

Reference Counter and destructor being called twice

From Dev

Meteor Router data function being called twice

From Dev

Why is my WCF ServiceAuthorizationManager being called twice on each request?

From Dev

Why is my spring boot stateless filter being called twice?

From Dev

Why is the +initialize method of Core Data managed objects being called twice?

From Dev

Every link_to on my rails 4 application is being called twice

From Dev

JSR303 custom validators being called twice

From Dev

Partial view not rendering and Action method being called twice

From Dev

Update inside React useState setter being called twice

Related Related

  1. 1

    HandleFunc being called twice

  2. 2

    page being called twice

  3. 3

    Why is viewDidLoad being called twice

  4. 4

    Why constructor is being called twice

  5. 5

    JS function being called twice?

  6. 6

    ViewPager Fragment being called twice

  7. 7

    Why constructor is being called twice

  8. 8

    Callback function being called twice

  9. 9

    Constructor of Part is being called twice

  10. 10

    Why is viewDidLoad being called twice

  11. 11

    Bind data to specific blade templates in Laravel 5.1 (Issue with view composer being called twice on nested template)

  12. 12

    Meteor Router data function being called twice

  13. 13

    Why is my onCreateView method being called twice?

  14. 14

    Prevent on('click') from being called twice

  15. 15

    javascript click being called twice and more

  16. 16

    Ninject, WebAPI and ExceptionFilterAttribute being called twice

  17. 17

    AngularJS Service in directive being called twice

  18. 18

    Controller being called twice in Ionic (AngularJS)

  19. 19

    Why DTM Data Element is being called twice?

  20. 20

    For some reason, paint() is being called twice

  21. 21

    Reference Counter and destructor being called twice

  22. 22

    Meteor Router data function being called twice

  23. 23

    Why is my WCF ServiceAuthorizationManager being called twice on each request?

  24. 24

    Why is my spring boot stateless filter being called twice?

  25. 25

    Why is the +initialize method of Core Data managed objects being called twice?

  26. 26

    Every link_to on my rails 4 application is being called twice

  27. 27

    JSR303 custom validators being called twice

  28. 28

    Partial view not rendering and Action method being called twice

  29. 29

    Update inside React useState setter being called twice

HotTag

Archive