Clerk error
Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware()
"Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware()" means auth() ran on a request that clerkMiddleware() never handled, so @clerk/nextjs throws and the page answers HTTP 500. The message lists three checks: clerkMiddleware() is used in your middleware or proxy file, the matcher matches this route, and with a src folder the file sits inside src. Clerk's docs say to name the file proxy.ts on Next.js 16 and middleware.ts on Next.js 15 and earlier. Fix the name, the folder or the matcher, then redeploy. Clerk's error page adds two causes: no ClerkProvider above the call, and a request for a missing static asset, which the matcher skips. Reproduced with @clerk/nextjs 7.9.23 and next 16.4.3 on 2026-10-31.
The full message in the server log
The text comes from authAuthHeaderMissing in packages/nextjs/src/server/errors.ts. On Next.js 16 it says "middleware or proxy", and in the local run its first bullet also named the file it expected. Clerk's docs say Next.js 15 and earlier print only "middleware". The error is thrown at the auth() call, so the stack points at your page or route handler, not at the proxy file.
Clerk: auth() was called but Clerk can't detect usage of clerkMiddleware(). Please ensure the following:
- Your middleware or proxy file exists at ./middleware.(ts|js) or proxy.(ts|js)
- clerkMiddleware() is used in your Next.js middleware or proxy file.
- Your middleware or proxy matcher is configured to match this route or page.
- If you are using the src directory, make sure the middleware or proxy file is inside of it.
For more details, see https://clerk.com/err/auth-middlewareWhere does the Clerk proxy.ts or middleware.ts file go?
Clerk's clerkMiddleware reference says to create proxy.ts at the root of the project, or in src/ if the project has one, and to name it middleware.ts on Next.js 15 and earlier. The file exports clerkMiddleware() and a matcher. This is the matcher from that page; it skips Next.js internals and static files and always runs for API routes and for /__clerk.
import { clerkMiddleware } from '@clerk/nextjs/server'
export default clerkMiddleware()
export const config = {
matcher: [
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
'/(api|trpc)(.*)',
'/__clerk/(.*)',
],
}Why does a narrow matcher still throw?
auth() needs the request to have passed through clerkMiddleware(). In a local run, a proxy.ts with matcher: ['/dashboard(.*)'] left a page at / that calls auth() answering 500 with this message, and the same page answered 200 once the matcher above replaced it. An AI-generated matcher that lists only the protected routes causes this on every public page that calls auth().
The file is right and the error still shows up
Clerk's error page names two other causes. The first is no ClerkProvider above the component that calls auth(); wrap the children in the root layout. The second is a request for a static asset that does not exist, such as an img with a wrong src: Next.js renders the 404 inside the root layout, but the matcher skipped the request, so clerkMiddleware() never ran. Fix the asset URL. Moving ClerkProvider into a sub-layout does not fix the missing asset, per that page. If the whole site fails after a deploy with no Clerk text in the log, see a Vercel middleware crash.
Checklist
How to fix it, then check the fix
- 01List which of the four possible files exist. You want one of them, in the right folder:
ls proxy.ts middleware.ts src/proxy.ts src/middleware.ts - 02Name the file proxy.ts on Next.js 16 and middleware.ts on Next.js 15 and earlier, and put it in src/ when your app folder is src/app.
- 03Check that it has export default clerkMiddleware() and a matcher that covers every route that calls auth(), currentUser() or getAuth(). Start from the matcher above and narrow it only for routes that never call Clerk.
- 04Check that the root layout wraps its children in ClerkProvider, then open the browser network tab on a failing page and fix any request that returns 404 for an image or script.
- 05Redeploy, open the failing route on the new deployment and check the function log: the message is gone and the route answers 200 or your own redirect.
Related
Related guides
Sources
Official docs behind this checklist
Browse all launch guides · Read resources · How to make and check your next change
FAQ
FAQ for builders before launch
Can I call auth() in a route the matcher skips?
No. auth() reads data that clerkMiddleware() attaches to the request, so on a route the matcher skips it throws this error. In the local run, a page at / failed with a matcher that only listed /dashboard.
Why does the message say "middleware or proxy"?
On Next.js 16 the middleware file is called proxy. Clerk's docs say the message says only "middleware" on Next.js 15 and earlier, and its docs name the file proxy.ts for 16 and middleware.ts for 15 and earlier.
Does the message mean Clerk is down?
Not by itself. The message ends with "there may be a runtime issue or a problem communicating with Clerk", but only after you have verified the file, the matcher and the src folder.