GuidesPrivate Pages

Once you haveauthenticated your user, you can use it to access private routes, like the dashboard.

While the current dashboard can be wrapped in the <LayoutDashboard>and ensure your user is authenticated, you can also create your own private pages.

In the following example, you can see how to leverage NextAuth to extract information from the session user.

import { getServerSession } from "next-auth";
import { authOptions } from "@/helpers/auth/auth.helpers";
import {findUserByEmail} from "@/helpers/models/user.helpers";
export default async function ProtectedPage() {
const session = await getServerSession(authOptions);
const user = await findUserByEmail(session.user.email)
return (
<>
<section className="max-w-xl mx-auto space-y-8">
<h1 className="text-3xl md:text-4xl font-extrabold">
User Dashboard
</h1>
<p>Hello {user.name}! 👋</p>
<p>Your email is {user.email}</p>
</section>
</>
);
}