My client component navbar does not refresh to show the most updated ui elements upon session changes

I have a navbar component that appears on every single page, including the login page and it is a client component.

There are two UI elements that will be shown depending on the useSession: if status is authenticated, it will show a UserButton (those round default profile picts that is a drop down) and if it is not authenticated/not logged in, it will show a sign in button.

The issue:
When i sign in, the sign in button will not change to the userbutton until i refresh the page. When i sign in, it will redirect to a settings page in case this information is relevant.

what ive tried:

  1. in the navbar “function” part (im new with nextjs so i dont know the exact terminology) i used a react.useeffect and inside i put router.refresh but apparently it doesnt work because those are for server side components. neither does router.reload.
    React.useEffect(() => {
        router.refresh();
        console.log("[main-nav-tsx][session]", { session });
        if (session === null) {
            console.log("[main-nav-tsx][session] NO USER SIGNED IN");
        }
    }, [router, session]);
  1. i tried using router.aspath but there is apparently an error because aspath is not a valid argument for router.replace
    React.useEffect(() => {
        if (status === 'authenticated' || status === 'unauthenticated') {
            router.replace(router.asPath);
        }
    }, [status, router]);
  1. i also tried adding CHOKIDAR_USEPOLLING=true to my .env file but it doesnt work.

what i expect:
i just need the navbar to do some form of reload/refresh every time we go to a new page (for example from locahost:3000/auth/login to locahost:3000/config/profile)

this is the main-nav.tsx component. it appears on every single page. im not sure if the refreshing of components has anything to do with my middleware, authentication, hooks/use-current-user.ts or what. in case it is important, i followed this tutorial

//src/components/main-nav.tsx

"use client"

import * as React from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { docsConfig } from "@/config/docs";
import { siteConfig } from "@/config/site";
import { cn } from "@/lib/utils";
import { Icons } from "@/components/icons";
import { LoginButton } from "./auth/login-button";
import { Button } from "./ui/button";
import { UserButton } from "@/components/auth/user-button";
import { useSession } from "next-auth/react";

export function MainNav() {
    const pathname = usePathname();
    const { data: session, status } = useSession();

    // Log the current session
    React.useEffect(() => {
        console.log("[main-nav-tsx][session]", { session });
        if (!session) {
            console.log("[main-nav-tsx][session] NO USER SIGNED IN");
        } else {
            console.log("[main-nav-tsx][session] USER SIGNED IN", session.user);
        }
    }, [session]);

    return (
        <div className="mr-4 hidden md:flex">
            <Link href="/" className="mr-6 flex items-center space-x-2">
                <Icons.logo className="h-6 w-6" />
                <span className="hidden font-bold sm:inline-block">
                    {siteConfig.name}
                </span>
            </Link>
            <nav className="flex items-center gap-4 text-sm lg:gap-6">
                {docsConfig.mainNav?.map((item) =>
                    item.href ? (
                        <Link
                            key={item.href}
                            href={item.href}
                            className={cn(
                                "transition-colors hover:text-foreground/80",
                                pathname === item.href
                                    ? "text-foreground"
                                    : "text-foreground/60"
                            )}
                        >
                            {item.title}
                        </Link>
                    ) : null
                )}
                {/* user button is to be shown only when user is logged in. 
                otherwise, show sign in.
                it works, but it doesnt auto refresh, i have to manually refresh the page */}
                {status === "authenticated" ? (
                    <UserButton />
                ) : (
                    <LoginButton>
                        <Button>Sign in</Button>
                    </LoginButton>
                )}
            </nav>
        </div>
    );
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật