Add a protected route
See original GitHub issueThanks so much for this example!
I’m starting to play around with Svelte and your setup with firebase auth in a store is very helpful. However I haven’t been able to set up a properly protected route. I tried setting it up in the load
function like in the real-world example, but stores aren’t available in <script context="module">
s. Then I tried setting up a redirect with goto
inside onMount
but the store is always unset at the beginning, so it always ends up trying to redirect as if there was no user signed in. It isn’t until after the onMount
runs that the onAuthStateChanged
in listen
kicks in and sets the auth store to the current user.
I’m wondering if I need to store the auth value in a cookie on top of the store or if there’s a better, svelte-way of doing things.
Could you add an example of a protected route in this example app?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:17 (9 by maintainers)
For anyone else reading, it boils down to the
.known
property indicating if the.user
property can be relied on yet. So until the.known
state is true, you shouldn’t decide anything based on the state of.user
as the SDK is still loading / checking the auth status.Another way of doing it is to make the auth store contain a promise, so you would instead
await
the auth state being known and set.The key part is it isn’t instant and whatever method you’re using, you have to wait for it to be set.
It is directly related actually since it queries your very unique and specific method in adopting Firebase. Looking through these issues it seems you really don’t have the right attitude for opensource projects - I appreciate your generosity in making this repo public however like @idr4n suggested I think it would be best to turn issues off going forward. Kindness and tolerance cost nothing.