DEV Community

Discussion on: Detecting a User's Authenticated State Client-Side in Next.js using an HttpOnly Cookie and Static Optimization

Collapse
 
justincy profile image
Justin

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.

Collapse
 
kiliman profile image
Kiliman

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.