Skip to content

Nextjs v16, auth0 v4.13.1: /auth/{login,logout,callback,profile,etc} not found #2436

@cmwhited

Description

@cmwhited

Checklist

Description

I recently updated from nextjs v15.5.2 to 16.0.6, and @auth0/nextjs-auth0 4.9.0 to v4.13.1.

After the updates, the /auth/login (and all other auth0 SDK mounted routes) return 404 not found; appear to not be mounted any longer.

I migrated from middleware.ts -> proxy.ts and used the Auth0Client.middleware function, passing it the raw Request object.

// proxy.ts
import { authClient } from '@/clients/auth'

export async function proxy(request: Request) {
  return await authClient.middleware(request)
}

export const config = {
  matcher: ['/admin/:path*'],
}

I updated my login links to use an <a> element instead of the nextjs Link element.

I even added a /auth/login/route.ts file and call the Auth0Client.startInteractiveLogin on a GET handler. This did start the login flow, but then the /auth/callback handler could not be found; same with /auth/logout, etc.

Reproduction

  1. Create a new nextjs app with latest: pnpm create next-app@latest
pnpm create next-app@latest
✔ What is your project named? … my-app
✔ Would you like to use the recommended Next.js defaults? › No, customize settings
✔ Would you like to use TypeScript? … No / Yes
✔ Which linter would you like to use? › ESLint
✔ Would you like to use React Compiler? … No / Yes
✔ Would you like to use Tailwind CSS? … No / Yes
✔ Would you like your code inside a `src/` directory? … No / Yes
✔ Would you like to use App Router? (recommended) … No / Yes
? Would you like to customize the import alias (`@/*` by default)? › No / Yes
  1. Installed latest nextjs: v16.0.6
  2. Installed @auth0/nextjs-auth0: v4.13.1
  3. Created a .env.local, copied in my key/secret
# .env.local

APP_BASE_URL="http://localhost:3000"
AUTH0_CLIENT_ID={{client_id}}
AUTH0_CLIENT_SECRET={{secret}}
AUTH0_DOMAIN={{domain}}
AUTH0_SECRET={{secret}}
  1. Created an auth0 client instance
// clients/auth.ts

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

export const authClient = new Auth0Client({
  signInReturnToPath: '/admin',
})
  1. Created a proxy.ts
// proxy.ts
import { authClient } from '@/clients/auth'

export async function proxy(request: Request) {
  return await authClient.middleware(request)
}

export const config = {
  matcher: ['/admin/:path*'],
}
  1. Updated my check sign in link to be an <a> element
// /app/admin/layout.tsx

import { authClient } from '@/clients/auth'

export const dynamic = 'force-dynamic'

export default async function AdminLandingPageLayout({ children }: Readonly<{ children: React.ReactNode }>) {
  const session = await authClient.getSession()

  if (session == null) {
    // user is not authenticated
    return (
      <div className="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
        <div className="sm:mx-auto sm:w-full sm:max-w-sm">
          <h2 className="mt-10 text-center text-2xl/9 font-bold tracking-tight text-gray-900">
            Sign in to your account
          </h2>
        </div>

        <div className="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
          <a
            href="/auth/login"
            className="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm/6 font-semibold text-white shadow-xs hover:bg-indigo-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
          >
            Sign in
          </a>
        </div>
      </div>
    )
  }

  return <div>{children}</div>
}
  1. Run the app pnpm run dev
  2. Open the browser: http://localhost:3000/admin
  3. Click the sign in link
  4. App shows the 404 Not Found
  5. Logs show 404 not found

Additional context

No response

nextjs-auth0 version

4.13.1

Next.js version

16.0.6

Node.js version

22.14.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions