According to the official firebase docs for implementation of google login, you create a listener/observer (onAuthStateChanged
) that will emit a user once your user has successfully gone through the login process.
When signing in, this works very well. You do signInWithPopup
or the full-screen variant and google takes care of collecting the relevant information and doing the login. If successful, onAuthStateChanged will emit the User object. From there, you have everything at your fingertips. It's very cool and I am super appreciative of the process here.
However, I am having trouble wrapping my brain around what happens when a user has logged in already and that logged-in user refreshes or re-approaches your app in whatever way. onAuthStateChanged
will fire up, but this is an asynchronous process, meaning that, for some time, the observer will emit nothing, but that lack of response could mean two different things. This brings me to my question:
How can you prevent visually displaying that you don't know whether the user is logged in or not? Is there some part of this implementation that I don't understand?
If, for example, I wait on that user object and then assign it to some redux store stuff, don't I always have a moment at the beginning of the app where I cannot possibly know whether a user is authenticated? I have to display the login page, even if I assume we're checking because the outcome may be that the user is not logged in. There's no signal to differentiate waiting for response and there being no response (because a user is not logged in)
You only have two options from the observer:
- A user is emitted because the user is signed in
- A user is not emitted because the request hasn't been completed or they're just simply not logged in.
That last one being two different possibilities is the problem, at least in my thinking.
Any advice?