Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextjs 15: Type "AppRouteHandlerFnContext" is not a valid type for the function's second argument. #1805

Open
6 tasks done
ltatakis-optaxe opened this issue Nov 14, 2024 · 4 comments

Comments

@ltatakis-optaxe
Copy link

Checklist

Description

Using the latest Nextjs the app works in the dev mode. But in the production next build

src/app/api/email/route.ts
Type error: Route "src/app/api/email/route.ts" has an invalid "POST" export:
  Type "AppRouteHandlerFnContext" is not a valid type for the function's second argument.
    Expected "Promise<any>", got "Record<string, string | string[]> | undefined".
      Expected "Promise<any>", got "undefined".

This occurs even with the simplest of code

import { withApiAuthRequired } from '@auth0/nextjs-auth0'
import { NextResponse } from 'next/server'

export const POST = withApiAuthRequired(async function email(req: Request) {
  return NextResponse.json({ success: true })
})

nextauthjs/next-auth has a similar issue and the fix is:

nextauthjs/next-auth@6cbd6a5

Reproduction

  1. Upgrade app to Nextjs 15
  2. run next build

Additional context

No response

nextjs-auth0 version

3.5.0

Next.js version

15.0.3

Node.js version

v22.11.0

@uprizingFaze
Copy link

@ltatakis-optaxe
Copy link
Author

ltatakis-optaxe commented Nov 14, 2024

@uprizingFaze Hello! Thank you for the quick reply. I have tried this but I am getting a wave of errors even before being able to check the build. I am following the docs here, but getting a lot of errors

Cannot find module '@auth0/nextjs-auth0' or its corresponding type declarations.
  There are types at '/...../node_modules/@auth0/nextjs-auth0/dist/client/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

1 import { useUser } from '@auth0/nextjs-auth0' 
src/pages/api/auth/[auth0].ts:1:57 - error TS2307: Cannot find module '@auth0/nextjs-auth0' or its corresponding type declarations.
  There are types at '/.../node_modules/@auth0/nextjs-auth0/dist/client/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

1 import { handleAuth, handleLogin, handleCallback } from '@auth0/nextjs-auth0'
src/lib/auth0Client/auth0.ts:1:29 - error TS2307: Cannot find module '@auth0/nextjs-auth0/server' or its corresponding type declarations.
  There are types at '/.../node_modules/@auth0/nextjs-auth0/dist/server/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

1 import { Auth0Client } from '@auth0/nextjs-auth0/server'

Our TS config compiler options look like

"compilerOptions": {
    "target": "es2017",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "strictNullChecks": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "types": ["node", "jest", "@testing-library/jest-dom"],
    "strictBindCallApply": true
  },

changing to NodeNext we still get

Import trace for requested module:
./src/pages/api/auth/[auth0].ts

./src/pages/api/auth/[auth0].ts
Attempted import error: 'handleLogin' is not exported from '@auth0/nextjs-auth0' (imported as 'handleLogin').

Import trace for requested module:
./src/pages/api/auth/[auth0].ts

./src/pages/api/auth/[auth0].ts
Attempted import error: 'handleCallback' is not exported from '@auth0/nextjs-auth0' (imported as 'handleCallback').

Import trace for requested module:
./src/pages/api/auth/[auth0].ts

./src/app/components/clientSideLayout.tsx
Attempted import error: 'UserProvider' is not exported from '@auth0/nextjs-auth0' (imported as 'UserProvider').


./src/app/api/email/route.ts
Attempted import error: 'withApiAuthRequired' is not exported from '@auth0/nextjs-auth0' (imported as 'withApiAuthRequired').

Import trace for requested module:
./src/app/api/email/route.ts

./src/app/api/notifications/subscription/route.ts
Attempted import error: 'withApiAuthRequired' is not exported from '@auth0/nextjs-auth0' (imported as 'withApiAuthRequired').

Import trace for requested module:
./src/app/api/notifications/subscription/route.ts

@uprizingFaze
Copy link

Hi! Sorry for the delay, I was checking how V4 works. Unfortunately, many things have changed, and what I consider the most relevant is that, as far as I read, the middleware matcher isn’t working at the moment. Each route has to be protected "manually." I’ll keep an eye on it since I have an app and am watching for any updates. I’ll let you know if anything comes up.

Everything is still a bit confusing; you can mention @guabu he can help you.
I made an example of what an app with Next.js 15 and Auth0 looks like. Check it out to get an idea: https://nextjs-15-auth0-v4.vercel.app/

@ltatakis-optaxe
Copy link
Author

I have not been able to get this work and now I am trying to upgrade to your latest version as it seems updating v3.5.0 is not an option for you.

Its not a pleasant experience and have opened a few more issues eg
#1810
#1809
which are blockers to me especially 1809

Also came across this issue along the way https://community.auth0.com/t/trying-out-v4-beta-receiving-generic-error/151286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants