Reputation: 16182
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.
Upvotes: 4
Views: 1046
Reputation: 18555
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.
Upvotes: 3