Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a protected route

See original GitHub issue

Thanks 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

CaptainCodemancommented, Sep 20, 2021

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.

kyleslopercommented, Oct 28, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create a Protected Route in React - MakeUseOf
Protected routes are those routes that only grant access to authorized users. This means that users must first meet certain conditions ...
Read more >
Implementing Protected Route and Authentication in React-JS
Protected Routes are routes that can only be accessed if a condition is met(usually, if user is properly authenticated). It returns a Route...
Read more >
React Router 6: Private Routes (alias Protected Routes)
Private Routes in React Router (also called Protected Routes) require a user being authorized to visit a route (read: page).
Read more >
Protected Routes and Authentication with React Router -
Protected routes let us choose which routes users can visit based on whether they are logged in. For example, you might have public...
Read more >
reactjs - How to create a protected route? - Stack Overflow
react-router-dom v5 ... Create a PrivateRoute component that consumes your auth context. const PrivateRoute = (props) => { const location = useLocation(); const...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found