Thanks for the example. I'm in the process of adding Firebase authentication.
I noticed that /api/checkAuth was being called on every page render. By adding [isAuthenticated] as a dependency in useEffect(), it only calls checkAuth on initial load/refresh and login/logout.
Actually, having an empty array [] makes it run only once. See the big yellow note that explains this at the end of the optimization section in the React hook docs.
For some reason though, it was calling checkAuth every time I navigated to a new page. So I guess the question is, is that the expectation?
Anyway, thanks again. I've expanded on your sample to use Firebase authentication. Also instead of having to mark each page as requiring authentication or not, I default to require authentication and have a withoutAuth HOC for those pages that are meant to be public.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for the example. I'm in the process of adding Firebase authentication.
I noticed that
/api/checkAuthwas being called on every page render. By adding[isAuthenticated]as a dependency inuseEffect(), it only calls checkAuth on initial load/refresh and login/logout.Actually, having an empty array
[]makes it run only once. See the big yellow note that explains this at the end of the optimization section in the React hook docs.Hmm. Interesting. I'm aware of that.
For some reason though, it was calling checkAuth every time I navigated to a new page. So I guess the question is, is that the expectation?
Anyway, thanks again. I've expanded on your sample to use Firebase authentication. Also instead of having to mark each page as requiring authentication or not, I default to require authentication and have a withoutAuth HOC for those pages that are meant to be public.