可以在Javascript中同步检查Firebase 3身份验证状态? [英] Possible to check Firebase 3 auth state synchronously in Javascript?
问题描述
目前我的应用程序正在使用授权状态更改回调来指示授权和我的应用程序中的主页面部分之间的移动。 (注意:我没有使用AngularFire)
在Firebase 3中,有 firebase.auth()。currentUser
如果firebase尚未完成从服务器拉取数据,currentUser设置为null。这个值在启动时可能是空的,但是在2秒后设置,而不需要用户对应用程序进行任何操作。
在我的应用程序中,用户授权状态应该是决定性因素他们看到的第一个屏幕,因为它本质上是异步的,他们看到授权页面,然后当前用户更新它将它们移动到主页,显示一个非常俗气的页面切换。
启动画面 - >登入 - >首页
登入网页的时间长短取决于互联网连线,这是非常明显的。
是否有任何方法来强制检查,看看用户是否登录,将返回true或false?我可以将一个异步方法放入承诺,问题是如果用户已经注销,则不会在启动时调用 onAuthStateChanged
回调。
没有。使用 .onAuthStateChanged
来确定用户身份验证状态。
从 currentUser
这是通过修改您的HTML / CSS修复的问题。默认视图不应该显示登录元素。仅在 .onAuthStateChanged
后面显示用户未登录。
Currently my application is making use of the authorization state change callbacks to indicate moving between the authorization and the main page sections in my app. (Note: I am not using AngularFire)
In Firebase 3 there is firebase.auth().currentUser
however the currentUser is set to null if firebase hasn't finished pulling the data from the server. This value may be null at startup but be set 2 seconds later without the user doing anything with the application.
In my app, the users authorization state should be the determining factor of the first screen that they see, because this is asynchrnous in nature, they're seeing the Authorization page, then after the currentUser updates it's moving them to the home page, which displays a very tacky page switch.
Splash Screen -> Login -> Home
The amount of time on the Login page depends on the internet connection, however on mobile data it is extremely noticable.
Is there any way to force a check to see if the user is logged in that will return true or false? I can make an asynchronous method into a promise, the issue is that the onAuthStateChanged
callback isn't called on startup if the user is logged out already.
No. Use .onAuthStateChanged
to determine the users Auth state.
In terms of the login showing / blinking prior to currentUser
that is an issue fixed by modifying your HTML/CSS. The default view should not display the login elements. Only display that after .onAuthStateChanged
tells you the user is not logged in.
这篇关于可以在Javascript中同步检查Firebase 3身份验证状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!