diff --git a/docs/docs/getting-started/client.md b/docs/docs/getting-started/client.md index 507f246ccc..335ced4d53 100644 --- a/docs/docs/getting-started/client.md +++ b/docs/docs/getting-started/client.md @@ -427,13 +427,14 @@ This only works on pages where you provide the correct `pageProps`, however. Thi ```js title="pages/index.js" import { unstable_getServerSession } from "next-auth/next" +import { authOptions } from './api/auth/[...nextauth]' ... -export async function getServerSideProps(ctx) { +export async function getServerSideProps({ req, res }) { return { props: { - session: await unstable_getServerSession(ctx) + session: await unstable_getServerSession(req, res, authOptions) } } } diff --git a/docs/docs/getting-started/example.md b/docs/docs/getting-started/example.md index dc95052cbc..c0fea307aa 100644 --- a/docs/docs/getting-started/example.md +++ b/docs/docs/getting-started/example.md @@ -97,6 +97,7 @@ To protect an API Route, you can use the [`unstable_getServerSession()`](/config ```javascript title="pages/api/restricted.js" showLineNumbers import { unstable_getServerSession } from "next-auth/next" +import { authOptions } from "./api/auth/[...nextauth]" export default async (req, res) => { const session = await unstable_getServerSession(req, res, authOptions) diff --git a/docs/docs/tutorials/securing-pages-and-api-routes.md b/docs/docs/tutorials/securing-pages-and-api-routes.md index 71dd33ae98..b7ef0c6449 100644 --- a/docs/docs/tutorials/securing-pages-and-api-routes.md +++ b/docs/docs/tutorials/securing-pages-and-api-routes.md @@ -62,6 +62,7 @@ You need to add this to every server rendered page you want to protect. Be aware ```js title="pages/server-side-example.js" import { useSession, unstable_getServerSession } from "next-auth/next" +import { authOptions } from "./api/auth/[...nextauth]" export default function Page() { const { data: session } = useSession() @@ -120,6 +121,7 @@ You can protect API routes using the `unstable_getServerSession()` method. ```js title="pages/api/get-session-example.js" import { unstable_getServerSession } from "next-auth/next" +import { authOptions } from "./api/auth/[...nextauth]" export default async (req, res) => { const session = await unstable_getServerSession(req, res, authOptions)