简体   繁体   English

可以在Javascript中同步检查Firebase 3 auth状态吗?

[英]Possible to check Firebase 3 auth state synchronously in Javascript?

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) (注意:我没有使用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. 在Firebase 3中有firebase.auth().currentUser但是如果firebase尚未完成从服务器中提取数据,则currentUser设置为null。 This value may be null at startup but be set 2 seconds later without the user doing anything with the application. 此值在启动时可能为null,但在2秒后设置,而无需用户对应用程序执行任何操作。

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. 在我的应用程序中,用户授权状态应该是他们看到的第一个屏幕的决定因素,因为这本质上是异步的,他们看到了授权页面,然后在currentUser更新之后将其移动到主页,显示一个非常俗气的页面切换。

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? 有没有办法强制检查用户是否登录将返回true或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. 我可以将异步方法转换为promise,问题是如果用户已经注销,则不会在启动时调用onAuthStateChanged回调。

No. Use .onAuthStateChanged to determine the users Auth state. .onAuthStateChanged 。使用.onAuthStateChanged来确定用户的Auth状态。

In terms of the login showing / blinking prior to currentUser that is an issue fixed by modifying your HTML/CSS. 关于在currentUser之前显示/闪烁的登录,这是通过修改HTML / CSS修复的问题。 The default view should not display the login elements. 默认视图不应显示登录元素。 Only display that after .onAuthStateChanged tells you the user is not logged in. 仅显示.onAuthStateChanged后告诉您用户未登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM