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.Solution:Jump to 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.2 Replies
Related code blocks:
server/context.ts
app/_trpc/serverClient
serverClient is actually working post login but on building my application and on public pages I'm getting the error.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.