© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•2y ago
Nicolai

I've set up clerk (core v2) with next-on

I've set up clerk (core v2) with next-on-pages for tRPC authorization.
I'm using the clerk middleware:
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";

const isProtectedRoute = createRouteMatcher(["/start(.*)"]);

export default clerkMiddleware(
  (auth, request) => {
    if (isProtectedRoute(request)) {
      auth().protect();
    }

    return NextResponse.next();
  },
  { debug: true },
);

export const config = {
  matcher: ["/((?!.+\\.[\\w]+$|_next)._)", "/", "/(api|trpc)(._)"],
};
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";

const isProtectedRoute = createRouteMatcher(["/start(.*)"]);

export default clerkMiddleware(
  (auth, request) => {
    if (isProtectedRoute(request)) {
      auth().protect();
    }

    return NextResponse.next();
  },
  { debug: true },
);

export const config = {
  matcher: ["/((?!.+\\.[\\w]+$|_next)._)", "/", "/(api|trpc)(._)"],
};

and creating a tRPC context like this:
const createContext = async (req: NextRequest) => {
  return createTRPCContext({
    headers: req.headers,
    auth: getAuth(req),
  });
};
const createContext = async (req: NextRequest) => {
  return createTRPCContext({
    headers: req.headers,
    auth: getAuth(req),
  });
};

but i'm constantly getting this error message in my tRPC requests:
            "message": "Clerk: getAuth() was called but Clerk can't detect usage of clerkMiddleware() (or the deprecated authMiddleware()). Please ensure the following:\n-  clerkMiddleware() (or the deprecated authMiddleware()) is used in your Next.js Middleware.\n- Your Middleware matcher is configured to match this route or page.\n- If you are using the src directory, make sure the Middleware file is inside of it.\n\nFor more details, see https://clerk.com/docs/quickstarts/nextjs\n",
            "message": "Clerk: getAuth() was called but Clerk can't detect usage of clerkMiddleware() (or the deprecated authMiddleware()). Please ensure the following:\n-  clerkMiddleware() (or the deprecated authMiddleware()) is used in your Next.js Middleware.\n- Your Middleware matcher is configured to match this route or page.\n- If you are using the src directory, make sure the Middleware file is inside of it.\n\nFor more details, see https://clerk.com/docs/quickstarts/nextjs\n",


anyone had this issue before? Any ideas on how to debug? Any thoughts at all?
I'd be really grateful!
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Update: I think I've got the Next.js app
Cloudflare DevelopersCDCloudflare Developers / next-on-pages
2y ago
I also have another issue with next-on-
Cloudflare DevelopersCDCloudflare Developers / next-on-pages
2y ago
anyone using baselime with next-on-pages
Cloudflare DevelopersCDCloudflare Developers / next-on-pages
2y ago
**Need help using KV with next-on-pages
Cloudflare DevelopersCDCloudflare Developers / next-on-pages
3y ago