import { getServerSession } from "next-auth/next" import { authOptions } from "../api/auth/[...nextauth]" import Layout from "../../components/layout" import type { GetServerSidePropsContext } from "next" import type { Session } from "next-auth" export default function ServerSidePage({ session }: { session: Session }) { // As this page uses Server Side Rendering, the `session` will be already // populated on render without needing to go through a loading stage. return (

Server Side Rendering

This page uses the getServerSession() method in getServerSideProps().

Using getServerSession() in{" "} getServerSideProps() is the recommended approach if you need to support Server Side Rendering with authentication.

The advantage of Server Side Rendering is this page does not require client side JavaScript.

The disadvantage of Server Side Rendering is that this page is slower to render.

SESSION: {JSON.stringify(session, null, 2)}
) } // Export the `session` prop to use sessions with Server Side Rendering export async function getServerSideProps(context: GetServerSidePropsContext) { return { props: { session: await getServerSession( context.req, context.res, authOptions ), }, } }