How to keep authenticated state on refresh?

I'm using firebase authentication for my app. I used useAuth hook from here. Integrate with react-router guide about redirect (Auth).

SignIn,SignOut function is working as expected. But when I try to refresh the page. It redirects to /login again.

My expected: Redirect to / route when authenticated.

I tried to add this code in PrivateRoute.js

  if (auth.loading) {
    return <div>authenticating...</div>;

So I can refresh the page without redirect to /login but it only show authenticating... when click the log out button.

Here is my code:

What I missed? Thanks!

Read more here:

Content Attribution

This content was originally published by Dũn at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: