Compare commits

...

3 Commits

Author SHA1 Message Date
Balázs Orbán
58e30a6af6 chore(release): bump package version(s) [skip ci] 2022-11-07 21:33:48 +01:00
Balázs Orbán
b7ff987baf docs: update unstable_getServerSession in RSC 2022-11-07 21:20:06 +01:00
Balázs Orbán
782812a52b fix(next): correctly parse headers with RSC (#5753)
* fix(next): correctly parse headers with RSC

* chore(dev): simplify/fix dev app

* make authOptions optional for RSC case
2022-11-07 20:19:14 +00:00
6 changed files with 9 additions and 11 deletions

View File

@@ -1,7 +1,6 @@
import { unstable_getServerSession } from "next-auth/next"
import { authOptions } from "pages/api/auth/[...nextauth]"
export default async function Page() {
const session = await unstable_getServerSession(authOptions)
const session = await unstable_getServerSession()
return <pre>{JSON.stringify(session, null, 2)}</pre>
}

View File

@@ -3,6 +3,6 @@ import { unstable_getServerSession } from "next-auth/next"
import { authOptions } from "../auth/[...nextauth]"
export default async (req, res) => {
const session = await unstable_getServerSession(authOptions)
const session = await unstable_getServerSession(req, res, authOptions)
res.json(session)
}

View File

@@ -75,10 +75,9 @@ You can also use `unstable_getServerSession` in Next.js' server components:
```tsx
import { unstable_getServerSession } from "next-auth/next"
import { authOptions } from "pages/api/auth/[...nextauth]"
export default async function Page() {
const session = await unstable_getServerSession(authOptions)
const session = await unstable_getServerSession()
return <pre>{JSON.stringify(session, null, 2)}</pre>
}
```

View File

@@ -75,10 +75,9 @@ You can also use `unstable_getServerSession` in Next.js' server components:
```tsx
import { unstable_getServerSession } from "next-auth/next"
import { authOptions } from "pages/api/auth/[...nextauth]"
export default async function Page() {
const session = await unstable_getServerSession(authOptions)
const session = await unstable_getServerSession()
return <pre>{JSON.stringify(session, null, 2)}</pre>
}
```

View File

@@ -1,6 +1,6 @@
{
"name": "next-auth",
"version": "4.16.3",
"version": "4.16.4",
"description": "Authentication for Next.js",
"homepage": "https://next-auth.js.org",
"repository": "https://github.com/nextauthjs/next-auth.git",

View File

@@ -94,6 +94,7 @@ export async function unstable_getServerSession(
]
| [NextApiRequest, NextApiResponse, NextAuthOptions]
| [NextAuthOptions]
| []
): Promise<Session | null> {
if (!experimentalWarningShown && process.env.NODE_ENV !== "production") {
console.warn(
@@ -105,7 +106,7 @@ export async function unstable_getServerSession(
experimentalWarningShown = true
}
const isRSC = args.length === 1
const isRSC = args.length === 0 || args.length === 1
if (
!experimentalRSCWarningShown &&
isRSC &&
@@ -122,11 +123,11 @@ export async function unstable_getServerSession(
let req, res, options: NextAuthOptions
if (isRSC) {
options = args[0]
options = args[0] ?? { providers: [] }
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { headers, cookies } = require("next/headers")
req = {
headers,
headers: Object.fromEntries(headers() as Headers),
cookies: Object.fromEntries(
cookies()
.getAll()