---
title: "Comment by Jason Chen on \"Client-Side Authentication in Next.js using Cookies\" | Hashnode"
description: "Hi, I enjoy your posts, always clear and insightful!😎 In the code snippet with useEffect , I wondered if missing dependencies could cause unexpected behavior?"
url: "https://hashnode.com/posts/client-side-authentication-in-nextjs-using-cookies/64c7bf528d1be10c482649ae/comment/64cd923413daa5cdc4003f83"
---

[Discussion](https://hashnode.com/posts/client-side-authentication-in-nextjs-using-cookies/64c7bf528d1be10c482649ae)

Comment [Client-Side Authentication in Next.js using Cookies](https://hashnode.com/posts/client-side-authentication-in-nextjs-using-cookies/64c7bf528d1be10c482649ae)

[Jason Chen](https://hashnode.com/@jason60810)

[Aug 5, 2023](https://hashnode.com/posts/client-side-authentication-in-nextjs-using-cookies/64c7bf528d1be10c482649ae/comment/64cd923413daa5cdc4003f83)

Hi, I enjoy your posts, always clear and insightful!😎

In the code snippet with `useEffect`, I wondered if missing dependencies could cause unexpected behavior?

```
useEffect(() => {
  if (!isAuthenticated && !currentUser.isLoading) {
    router.push("/"); // or login page
  }
}, 
// missing isAuthenticated and 
// currentUser.isLoading
[Component, isAuthenticated, currentUser.isLoading]);
```

Great job, and eager for your future posts!

[Hoh Shen Yien](https://hashnode.com/@ShenYien)

[Aug 5, 2023](https://hashnode.com/posts/client-side-authentication-in-nextjs-using-cookies/64c7bf528d1be10c482649ae/comment/64cd923413daa5cdc4003f83#reply-64cdc91b3d3aabc9723f82bc)

Thanks Jason.

Regarding the missing dependencies, it's actually intended!

Rather, putting more variables in the dependencies is what brings the undesirable behavior sometimes 😅. Like in the codes, I want to run the function only when the page changes, so I could either put `router.asPath` or `Component`, and if I also include `currentUser.isLoading`, it will run an additional time, which is undesirable.

As for the `isAuthenticated`, it is not a memoized variable, so putting it in the dependencies will actually result in the `useEffect` being run for every render, which is not what we want (never put an unmemoized variable in `useEffect`).

But of course, my logic here assumes that the user will be redirected to another page after logging in, which might not always be the case.
