SwaroopS
tRPC3y ago
4 replies
Swaroop

How to pass headers from serverActions in Next.js App router.

I'm using tRPC with Clerk auth provider in Next.js App directory. I created a
serverClient
to use tRPC on server-side but the context is complaining about not having request headers, it throws this even on building my application.

Attached error and my file structure.
image.png
image.png
Solution
Resolved it by moving clerk
auth()
to tRPC middleware with that server don't need to pass or the inner context doesn't need to have Clerk
auth()
as it doesn't depend on req or res objects.
Was this page helpful?