Firebase停止侦听AuthStateChanged [英] Firebase stop listening onAuthStateChanged
问题描述
firebase.auth ().onAuthStateChanged(function(user){
//处理
});
但是,我无法找到引用remove auth状态更改侦听器的文档中的任何地方。在Firebase.Auth类中有一个特殊的函数叫做 removeAuthTokenListener
。不幸的是,它没有记录( Firebase文档参考)。
通过浏览器的网络控制台。
var auth = firebase.auth();
auth.removeAuthTokenListener;
打印一个带有一个参数的函数定义。我试图做到以下几点:$ b
$ b $ p $ this.authListener = firebase.auth()。onAuthStateChanged(function(user){.. 。});
firebase.auth()。removeAuthTokenListener(this.authListener);
但是没有做任何事情。根据 auth.Auth#onAuthStateChanged>文档, onAuthStateChanged()
函数返回
观察者的取消订阅功能。
所以你可以:
var unsubscribe = firebase.auth()。onAuthStateChanged(function(user){
//处理
});
然后:
退订();
As of version ^3.0.0, I'm having a difficult time removing the auth state change listener.
To start the listener per the documentation:
firebase.auth().onAuthStateChanged(function (user) {
// handle it
});
However, I cannot find anywhere in the documentation that refers to a remove auth state change listener. There is peculiar function on the Firebase.Auth class called removeAuthTokenListener
. Unfortunately it's not documented (firebase docs reference).
Via your browser's web console.
var auth = firebase.auth();
auth.removeAuthTokenListener;
prints a function definition that takes one parameter. I tried to do the following:
this.authListener = firebase.auth().onAuthStateChanged(function (user) {...});
firebase.auth().removeAuthTokenListener(this.authListener);
but that didn't do anything.
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) {
// handle it
});
And then:
unsubscribe();
这篇关于Firebase停止侦听AuthStateChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!