-
Notifications
You must be signed in to change notification settings - Fork 432
Open
Labels
Description
Checklist
- The issue can be reproduced in the nextjs-auth0 sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
Hi,
This is semi-related to #2219. In the latest version of Node.js, the nodejs
runtime is now stable: https://nextjs.org/blog/next-15-5#nodejs-middleware-stable
I'm getting the same error as in #2219 when I enable this while following the middleware example in https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#middleware-2 with the nodejs
runtime enabled.
Reproduction
https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#middleware-2
import { NextRequest, NextResponse } from "next/server";
import { auth0 } from "./lib/auth0"; // Adjust path if your auth0 client is elsewhere
export async function middleware(request: NextRequest) {
const authRes = await auth0.middleware(request);
if (request.nextUrl.pathname.startsWith("/auth")) {
return authRes;
}
const session = await auth0.getSession(request);
if (!session) {
// user is not authenticated, redirect to login page
return NextResponse.redirect(
new URL("/auth/login", request.nextUrl.origin)
);
}
const accessToken = await auth0.getAccessToken(request, authRes);
// the headers from the auth middleware should always be returned
return authRes;
}
export const config = {
runtime: "nodejs",
matcher: [
/*
* Match all request paths except for the ones starting with:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
*/
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
],
};
Additional context
No response
nextjs-auth0 version
4.9.0
Next.js version
15.5.2
Node.js version
v22.14.0