feat: Add session update for dashboard and admin pages

This commit is contained in:
wood chen 2025-02-21 23:59:22 +08:00
parent 47e9d686d6
commit d5465246cb

View File

@ -21,11 +21,18 @@ import { ThemeToggle } from "../theme-toggle";
import { Button } from "../ui/button";
export function NavBar() {
const { data: session, status } = useSession();
const { data: session, status, update } = useSession();
const router = useRouter();
const pathname = usePathname();
const user = session?.user;
// 在 dashboard 或 admin 页面时强制刷新一次 session
useEffect(() => {
if (pathname?.startsWith("/dashboard") || pathname?.startsWith("/admin")) {
update();
}
}, [pathname, update]);
const handleSignOut = async () => {
await signOut({ redirect: false });
router.refresh();