


const ProtectedPage = () => {
const { data: session, status } = useSession();
const router = useRouter();
// If session is loading, display a loading indicator
if (status === "loading") {
return <p>Loading...</p>;
}
// If there's no session or the user role is not "user", redirect to unauthorized
if (!session || session.user?.role !== "user") {
router.push("/unauthorized");
return null; // Prevents rendering protected content
}
return (
<div>
<h1>Welcome to the Protected Page</h1>
<p>Your role: {session.user.role}</p>
</div>
);
};