Skip to content

Commit 4d143c5

Browse files
committed
fix: await dynamic APIs as per Next.js 15 changes
1 parent 15c046c commit 4d143c5

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

packages/next-auth/src/next/index.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import type {
1313
AuthAction,
1414
NextAuthRequest,
1515
NextAuthResponse,
16+
Awaitable,
1617
} from "../core/types"
1718

1819
interface RouteHandlerContext {
19-
params: { nextauth: string[] }
20+
params: Awaitable<{ nextauth: string[] }>
2021
}
2122

2223
async function NextAuthApiHandler(
@@ -74,19 +75,17 @@ async function NextAuthRouteHandler(
7475

7576
// eslint-disable-next-line @typescript-eslint/no-var-requires
7677
const { headers, cookies } = require("next/headers")
77-
const nextauth = context.params?.nextauth
78+
const nextauth = (await context.params)?.nextauth
7879
const query = Object.fromEntries(req.nextUrl.searchParams)
7980
const body = await getBody(req)
8081
const internalResponse = await AuthHandler({
8182
req: {
8283
body,
8384
query,
8485
cookies: Object.fromEntries(
85-
cookies()
86-
.getAll()
87-
.map((c) => [c.name, c.value])
86+
(await cookies()).getAll().map((c) => [c.name, c.value])
8887
),
89-
headers: Object.fromEntries(headers() as Headers),
88+
headers: Object.fromEntries((await headers()) as Headers),
9089
method: req.method,
9190
action: nextauth?.[0] as AuthAction,
9291
providerId: nextauth?.[1],
@@ -176,7 +175,7 @@ export async function getServerSession<
176175
O extends GetServerSessionOptions,
177176
R = O["callbacks"] extends { session: (...args: any[]) => infer U }
178177
? U
179-
: Session
178+
: Session,
180179
>(...args: GetServerSessionParams<O>): Promise<R | null> {
181180
const isRSC = args.length === 0 || args.length === 1
182181

@@ -187,11 +186,9 @@ export async function getServerSession<
187186
// eslint-disable-next-line @typescript-eslint/no-var-requires
188187
const { headers, cookies } = require("next/headers")
189188
req = {
190-
headers: Object.fromEntries(headers() as Headers),
189+
headers: Object.fromEntries((await headers()) as Headers),
191190
cookies: Object.fromEntries(
192-
cookies()
193-
.getAll()
194-
.map((c) => [c.name, c.value])
191+
(await cookies()).getAll().map((c) => [c.name, c.value])
195192
),
196193
}
197194
res = { getHeader() {}, setCookie() {}, setHeader() {} }
@@ -236,7 +233,7 @@ export async function unstable_getServerSession<
236233
O extends GetServerSessionOptions,
237234
R = O["callbacks"] extends { session: (...args: any[]) => infer U }
238235
? U
239-
: Session
236+
: Session,
240237
>(...args: GetServerSessionParams<O>): Promise<R | null> {
241238
if (!deprecatedWarningShown && process.env.NODE_ENV !== "production") {
242239
console.warn(

0 commit comments

Comments
 (0)