TRPC Middleware

How can I create a TRPC middleware function where I can inspect the HTTP headers? I'm in trpc.ts in the server and see the documentation, but I can't piece it all together.
export const activatedMiddleware = t.middleware(async (opts) => {
const { ctx } = opts;

return opts.next(opts);

})
export const activatedMiddleware = t.middleware(async (opts) => {
const { ctx } = opts;

return opts.next(opts);

})
I have this so far and would like to check the request headers.
1 Reply
willm
willm14mo ago
Found a solution:
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";

// ...

export const createTRPCContext = (opts: CreateNextContextOptions) => {
const { req } = opts;

return {
...createInnerTRPCContext({}),
req,
};
};
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";

// ...

export const createTRPCContext = (opts: CreateNextContextOptions) => {
const { req } = opts;

return {
...createInnerTRPCContext({}),
req,
};
};