diff --git a/packages/next-auth/src/lib/index.ts b/packages/next-auth/src/lib/index.ts index 4c7c686242..1e1d95458d 100644 --- a/packages/next-auth/src/lib/index.ts +++ b/packages/next-auth/src/lib/index.ts @@ -163,7 +163,9 @@ export function initAuth( const auth = await authResponse.json() for (const cookie of authResponse.headers.getSetCookie()) - response.headers.append("set-cookie", cookie) + if ("headers" in response) + response.headers.append("set-cookie", cookie) + else response.appendHeader("set-cookie", cookie) return auth satisfies Session | null } @@ -209,7 +211,8 @@ export function initAuth( const auth = await authResponse.json() for (const cookie of authResponse.headers.getSetCookie()) - response.headers.append("set-cookie", cookie) + if ("headers" in response) response.headers.append("set-cookie", cookie) + else response.appendHeader("set-cookie", cookie) return auth satisfies Session | null })