You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a Single Page Application context, routes must be protected before being flashed to end-user. To guard private routes, one then needs to first show a loading page while we WAIT for some isLoggedIn status to resolve, and then decide if the user can actually access to the page or not. So, something like this:
So far so good. The thing is, when a user manually refreshes his browser (hitting F5 for example), this $isLoggedIn variable always starts as false UNTIL the Auth system is actually loaded. So we need to first be sure that the Auth system, in this case firebase-auth-lite has actually been given the time to load and look for any user. So, something like this:
// using Svelte
{#if $isLoadingAuthInfos}
<Spinner>Wait while loading Auth Infos...</Spinner>
{:else}
{#if $isLoggedIn}
<PrivateStuff />
{:else}
<PublicStuff />
{/if}
{/if}
Now, with this logic in mind, I quite struggle to implement it using firebase-auth-lite. In fact, I am not sure if I understand correctly the nature of the auth.listen() function, so please forgive me if I have incorrect assumptions, but this is what I have been trying so far:
In my mind, $isLoadingAuthInfos.set(true) should always be called, even if no user was found, right?!
As of version 0.8.9, the auth.listen(cb) callback is never fired if no user was found.
So what would be the correct way to know if firebase-auth-lite actually FINISHED to check for any logging? Hopefully I have not missed something but it looks to me that there is no way to be informed that firebase-auth-lite TRIED to look for some user and failed to found one.
Anyways, thank you for the library !
The text was updated successfully, but these errors were encountered:
From the source code, I can see that the emit() function is the one responsible for actually triggering all callback function from auth.listen(cb). So for now, I am using this:
In a Single Page Application context, routes must be protected before being flashed to end-user. To guard private routes, one then needs to first show a
loading
page while we WAIT for someisLoggedIn
status to resolve, and then decide if the user can actually access to the page or not. So, something like this:So far so good. The thing is, when a user manually refreshes his browser (hitting F5 for example), this
$isLoggedIn
variable always starts asfalse
UNTIL the Auth system is actually loaded. So we need to first be sure that the Auth system, in this casefirebase-auth-lite
has actually been given the time to load and look for any user. So, something like this:Now, with this logic in mind, I quite struggle to implement it using
firebase-auth-lite
. In fact, I am not sure if I understand correctly the nature of theauth.listen()
function, so please forgive me if I have incorrect assumptions, but this is what I have been trying so far:In my mind,
$isLoadingAuthInfos.set(true)
should always be called, even if no user was found, right?!As of version
0.8.9
, theauth.listen(cb)
callback is never fired if no user was found.So what would be the correct way to know if
firebase-auth-lite
actually FINISHED to check for any logging? Hopefully I have not missed something but it looks to me that there is no way to be informed thatfirebase-auth-lite
TRIED to look for some user and failed to found one.Anyways, thank you for the library !
The text was updated successfully, but these errors were encountered: