Skip to content

Commit

Permalink
fix: await dynamic APIs as per Next.js 15 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Oct 24, 2024
1 parent 15c046c commit 4d143c5
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions packages/next-auth/src/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import type {
AuthAction,
NextAuthRequest,
NextAuthResponse,
Awaitable,
} from "../core/types"

interface RouteHandlerContext {
params: { nextauth: string[] }
params: Awaitable<{ nextauth: string[] }>
}

async function NextAuthApiHandler(
Expand Down Expand Up @@ -74,19 +75,17 @@ async function NextAuthRouteHandler(

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { headers, cookies } = require("next/headers")
const nextauth = context.params?.nextauth
const nextauth = (await context.params)?.nextauth
const query = Object.fromEntries(req.nextUrl.searchParams)
const body = await getBody(req)
const internalResponse = await AuthHandler({
req: {
body,
query,
cookies: Object.fromEntries(
cookies()
.getAll()
.map((c) => [c.name, c.value])
(await cookies()).getAll().map((c) => [c.name, c.value])
),
headers: Object.fromEntries(headers() as Headers),
headers: Object.fromEntries((await headers()) as Headers),
method: req.method,
action: nextauth?.[0] as AuthAction,
providerId: nextauth?.[1],
Expand Down Expand Up @@ -176,7 +175,7 @@ export async function getServerSession<
O extends GetServerSessionOptions,
R = O["callbacks"] extends { session: (...args: any[]) => infer U }
? U
: Session
: Session,
>(...args: GetServerSessionParams<O>): Promise<R | null> {
const isRSC = args.length === 0 || args.length === 1

Expand All @@ -187,11 +186,9 @@ export async function getServerSession<
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { headers, cookies } = require("next/headers")
req = {
headers: Object.fromEntries(headers() as Headers),
headers: Object.fromEntries((await headers()) as Headers),
cookies: Object.fromEntries(
cookies()
.getAll()
.map((c) => [c.name, c.value])
(await cookies()).getAll().map((c) => [c.name, c.value])
),
}
res = { getHeader() {}, setCookie() {}, setHeader() {} }
Expand Down Expand Up @@ -236,7 +233,7 @@ export async function unstable_getServerSession<
O extends GetServerSessionOptions,
R = O["callbacks"] extends { session: (...args: any[]) => infer U }
? U
: Session
: Session,
>(...args: GetServerSessionParams<O>): Promise<R | null> {
if (!deprecatedWarningShown && process.env.NODE_ENV !== "production") {
console.warn(
Expand Down

0 comments on commit 4d143c5

Please sign in to comment.