previously i was wasting time with firebase.auth.currentUser
which is giving me null
when application loads, and i need auth user right when application loads(or a callback will also work for me). then i decide to use onAuthStateChanged
but now i am unable to unsubscribe it and it is firing again and again, i only want it to give me suth and destroy for ever instantly
So, How can i unsubscribe this thing:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
}
});
frank answered this question here: Firebase stop listening onAuthStateChanged
According to the documentation, the onAuthStateChanged() function returns
The unsubscribe function for the observer. So you can just:
var unsubscribe = firebase.auth().onAuthStateChanged(function (user) {
if (user) {
// User is signed in.
}
});
unsubscribe();//this line will unsubscribe the observable :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With