Skip to content

Commit

Permalink
docs: fix unstable_getServerSession arguments (#4815)
Browse files Browse the repository at this point in the history
* chore(docs): fix unstable_getServerSession arguments

* chore: add authOptions import
  • Loading branch information
ndom91 committed Jul 3, 2022
1 parent 993c0f4 commit 01cd6b0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/docs/getting-started/client.md
Expand Up @@ -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)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/docs/getting-started/example.md
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/tutorials/securing-pages-and-api-routes.md
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

1 comment on commit 01cd6b0

@vercel
Copy link

@vercel vercel bot commented on 01cd6b0 Jul 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.