Firebase Android Onauthstatechanged Called Twice

Firebase onAuthStateChanged is being called twice upon login

Yes this is normal, onAuthStateChanged will keep triggering. You can prevent from multiple calls with this code:

var authFlag = true;
firebase.auth().onAuthStateChanged((res) => {
if(res && authFlag) {
console.log('Firebase - onAuthStateChanged', {res})
authFlag = false;
//rest of your code

Why is Firebase Auth Signin and login segue being called twice

As this

Auth.auth().addStateDidChangeListener { auth, user in

triggers when login auth happens and causes a segue from this part

usersReference.observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
let value = snapshot.value as? NSDictionary
let name = value?["username"] as? String ?? ""
self.userName = name
self.performSegue(withIdentifier: "alreadyLoggedIn", sender: nil)
})


Related Topics



Leave a reply



Submit