Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i unsubscribe to onAuthStateChanged [duplicate]

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.
   }
});
like image 288
Inzamam Malik Avatar asked Mar 13 '17 11:03

Inzamam Malik


1 Answers

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 :-)
like image 66
Inzamam Malik Avatar answered Nov 07 '22 09:11

Inzamam Malik