Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase addStateDidChangeListener

I am pretty new to Firebase. I am trying to check if the user is logged in or not, and by referring to the Firebase doc, the recommended way of doing it would be adding a FIRAuthStateDidChangeListenerHandle.

My code is as follows:

  handle = FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
        //here, we add code to see if we are supposed to be loggin or not
        print("hello world")
        if user != nil{
            self.isLogin = true
        }else{
            self.isLogin = false
        }
    })

However, after I checked, it seems that FirAuth.auth() is a nil and the entire block is not called at all.

Any one knows what is wrong here?

like image 286
progammingBeignner Avatar asked Nov 28 '25 21:11

progammingBeignner


1 Answers

This looks like an improperly set up Firebase. Did you follow all the steps here? Specifically, did you, in your AppDelegate, call FIRApp.configure()? Without this configuration call your FIRAuth would likely be nil.

like image 147
BHendricks Avatar answered Nov 30 '25 11:11

BHendricks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!