Skip to content

Commit

Permalink
fix(next): fix Turbopack compat issue with next/*.js (#11551)
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 authored Aug 8, 2024
1 parent 1a3de31 commit 23892e7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/next-auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ import type {
AppRouteHandlerFn,
AppRouteHandlerFnContext,
} from "./lib/types.js"
import type { NextRequest } from "next/server.js"
// @ts-expect-error Next.js does not yet correctly use the `package.json#exports` field
import type { NextRequest } from "next/server"
import type { NextAuthConfig, NextAuthRequest } from "./lib/index.js"
export { AuthError, CredentialsSignin } from "@auth/core/errors"

Expand Down
6 changes: 4 additions & 2 deletions packages/next-auth/src/lib/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Auth, raw, skipCSRFCheck, createActionURL } from "@auth/core"
import { headers as nextHeaders, cookies } from "next/headers.js"
import { redirect } from "next/navigation.js"
// @ts-expect-error Next.js does not yet correctly use the `package.json#exports` field
import { headers as nextHeaders, cookies } from "next/headers"
// @ts-expect-error Next.js does not yet correctly use the `package.json#exports` field
import { redirect } from "next/navigation"

import type { NextAuthConfig } from "./index.js"
import type { NextAuthResult, Session } from "../index.js"
Expand Down
3 changes: 2 additions & 1 deletion packages/next-auth/src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextRequest } from "next/server.js"
// @ts-expect-error Next.js does not yet correctly use the `package.json#exports` field
import { NextRequest } from "next/server"
import type { NextAuthConfig } from "./index.js"
import { setEnvDefaults as coreSetEnvDefaults } from "@auth/core"

Expand Down
15 changes: 6 additions & 9 deletions packages/next-auth/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Auth, createActionURL, type AuthConfig } from "@auth/core"
import { headers } from "next/headers.js"
import { NextResponse } from "next/server.js"
// @ts-expect-error Next.js does not yet correctly use the `package.json#exports` field
import { headers } from "next/headers"
// @ts-expect-error Next.js does not yet correctly use the `package.json#exports` field
import { NextResponse } from "next/server"
import { reqWithEnvURL } from "./env.js"

import type { AuthAction, Awaitable, Session } from "@auth/core/types"
Expand All @@ -10,11 +12,8 @@ import type {
NextApiResponse,
} from "next"
import type { AppRouteHandlerFn } from "./types.js"
import type {
NextFetchEvent,
NextMiddleware,
NextRequest,
} from "next/server.js"
// @ts-expect-error Next.js does not yet correctly use the `package.json#exports` field
import type { NextFetchEvent, NextMiddleware, NextRequest } from "next/server"

/** Configure NextAuth.js. */
export interface NextAuthConfig extends Omit<AuthConfig, "raw"> {
Expand Down Expand Up @@ -163,7 +162,6 @@ export function initAuth(
// API Routes, getServerSideProps
const request = "req" in args[0] ? args[0].req : args[0]
const response: any = "res" in args[0] ? args[0].res : args[1]
// @ts-expect-error -- request is NextRequest
const _config = await config(request)
onLazyLoad?.(_config)

Expand Down Expand Up @@ -265,7 +263,6 @@ async function handleAuth(
const augmentedReq = request as NextAuthRequest
augmentedReq.auth = auth
response =
// @ts-expect-error
(await userMiddlewareOrRoute(augmentedReq, args[1])) ??
NextResponse.next()
} else if (!authorized) {
Expand Down
3 changes: 2 additions & 1 deletion packages/next-auth/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NextRequest } from "next/server.js"
// @ts-expect-error Next.js does not yet correctly use the `package.json#exports` field
import type { NextRequest } from "next/server"

/**
* AppRouteHandlerFnContext is the context that is passed to the handler as the
Expand Down

0 comments on commit 23892e7

Please sign in to comment.