Get session

Hello, im trying to redirect not authenticated user to login page. But it does not redirect me My code:
"use client";
import { authClient } from "@/lib/auth-client"
import { useRouter } from "next/navigation";

export default function DashboardPage() {
const { data: session } =authClient.getSession();
const router = useRouter();
if (!session) {
router.push("/sign-in");
}

return (
<div>
<h1>Dashboard</h1>
</div>
);
}
"use client";
import { authClient } from "@/lib/auth-client"
import { useRouter } from "next/navigation";

export default function DashboardPage() {
const { data: session } =authClient.getSession();
const router = useRouter();
if (!session) {
router.push("/sign-in");
}

return (
<div>
<h1>Dashboard</h1>
</div>
);
}
Where did i do it wrong ?
Solution:
you need to use authClient.useSession not getSession
Jump to solution
2 Replies
Solution
bekacru
bekacru3w ago
you need to use authClient.useSession not getSession
wvn
wvnOP3w ago
Oh thank you

Did you find this page helpful?