如何解决Firebase onAuthStateChanged触发2x(初始化和解析)?

时间:2016-11-26 17:35:38

标签: firebase firebase-authentication

我一直无法找到解决此问题的有效方法。问题是languitar@miles ~/code/rust (master)> brew info gtk+3 gtk+3: stable 3.22.4 (bottled) Toolkit for creating graphical user interfaces http://gtk.org/ /usr/local/Cellar/gtk+3/3.22.4 (1,395 files, 70.0M) * Poured from bottle on 2016-11-26 at 17:11:24 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gtk+3.rb ==> Dependencies Build: pkg-config ✔ Required: gdk-pixbuf ✔, atk ✔, gobject-introspection ✔, libepoxy ✔, pango ✔, glib ✔, hicolor-icon-theme ✔ Recommended: gsettings-desktop-schemas ✔ Optional: jasper ✔ 在初始化时会执行一次,在结算时会再次执行。由于我的应用程序根据身份验证状态加载视图,因此初始化始终返回一个不可靠的值。

对此有一个强有力的解决方案吗?或者这不是问题,我只是疯了吗?

我看了很多,只发现了黑客或变通办法。

一对夫妇:

Firebase Android onAuthStateChanged called twice

Possible to check Firebase 3 auth state synchronously in Javascript?

1 个答案:

答案 0 :(得分:0)

onAuthStateChanged将始终在初始化时触发。但是,除非当前Firebase Id令牌发生更改(退出或新登录事件),否则不应再次触发。但是,请记住,firebase Id令牌每小时左右刷新一次,因此刷新令牌时每小时都会不断触发。您可以在侦听器中添加逻辑以检查用户是否已更改,并忽略同一用户是否仍然登录。如果您发现任何其他行为,请通知Firebase团队进行修复。