Using Clerk's getAuth() helper causes withClerkMiddleware to be unrecognized
Hi there,
Recently, I was following Theo's T3 stack tutorial on YouTube. When attempting to use the Clerk
Steps to Reproduce:
The
Actual Result:
An error message is thrown stating that the
Fixes Attempted:
Recently, I was following Theo's T3 stack tutorial on YouTube. When attempting to use the Clerk
getAuth() helper function in the trpc.ts file of the T3 stack application, an error is thrown stating that the withClerkMiddleware function must be added to the Next.js middleware.ts file. Prior to using the getAuth() helper function, Clerk was working fine and recognized that withClerkMiddleware had already been added to the middleware.ts file.Steps to Reproduce:
- Follow Theo's T3 stack tutorial on YouTube.
- At timestamp 1:21:28 in the tutorial, introduce the Clerk
getAuth()helper function in thetrpc.ts fileto retrieve the authentication state for a user based on theNextApiRequestargument passed to it. - Run the application using
command from the project's root directory .npm run dev - Observe the following error message (screenshot attached):
tRPC failed on <no-path>: You need to use "withClerkMiddleware" in your Next.js middleware file. You also need to make sure that your middleware matcher is configured correctly and matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs
The
getAuth() helper function should be able to retrieve the authentication state for a user without causing any errors.Actual Result:
An error message is thrown stating that the
withClerkMiddleware function must be added to the middleware.ts file, and to check that Clerk has been properly configured.Fixes Attempted:
- Deleted
.nextand restarted Next.js dev server using
command.npm run dev - Reinstalled
@clerk/nextjsNPM package. - Reconfigured
middleware.tsfrom scratch based on example from Clerk's quickstart documentation for Next.js.

YouTubeTheo - t3․gg
I've never worked this hard on a video before. I really hope y'all can benefit from this 
GITHUB REPO https://github.com/t3dotgg/chirp
DEPLOYED APP https://xn--uo8h.t3.gg/
GET A JACKET IF YOU'RE COOL LIKE THAT https://shop.t3.gg/
ALL MY VIDEOS ARE POSTED EARLY ON PATREON https://www.patreon.com/t3dotgg
Everything else (Twitch, Twitter, Discor...
GITHUB REPO https://github.com/t3dotgg/chirp
DEPLOYED APP https://xn--uo8h.t3.gg/
GET A JACKET IF YOU'RE COOL LIKE THAT https://shop.t3.gg/
ALL MY VIDEOS ARE POSTED EARLY ON PATREON https://www.patreon.com/t3dotgg
Everything else (Twitch, Twitter, Discor...

Clerk is the easiest way to add authentication and user management to your Next.js application