Skip to content

Headers.append: xxx is an invalid header value #2311

@kennethaasan

Description

@kennethaasan

Checklist

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions